/****************************************
 * 			
 * 		 	wdk的核心扩展类库
 * 
 * 
 * 
 ****************************************/
/************************************
 * 		全局事件
 ************************************/
window.onerror = function(message, url, line){ 
	alert("脚本运行错误。\n错误信息："+ message +"\n错误页面：" + url + "\n错误位置：" + line);
};
/*//首先进行session检测，如果为空，则跳到首页
	var _data = {};
	$.cuajax({
	  	url:'wdk?action=wdk.public&method=session_test&ajaxparam='+new Date().getTime(),
		method:"post", 
		timeout:WDK_Timeout,
		data:_data,   
		success:function(result) {
			var jres = $.str2json(result);
			if("1"==jres.code){
				alert("脚本运行错误。\n错误信息："+ message +"\n错误页面：" + url + "\n错误位置：" + line);
				//			$.getRoot().$.messager.alert('信息提示',"脚本运行错误。<br>错误信息："+ message +"<br>错误页面：" + url + "<br>错误位置：" + line,'error');
				return true; 
			}else{
			//	alert(jres.desc);
				$.timeout();
			}
		},
		error:function(result){
//			alert('网络错误！result='+result);
			$.getRoot().$.messager.alert('信息提示','网络错误：'+result,'error');
		}
	});
};
*/
/**
 * 全局键盘事件监控，屏蔽浏览器默认行为按键如下：
 * 		1、116 == window.event.keyCode 		//屏蔽 F5  
 * 		2、122 == window.event.keyCode	 	//屏蔽 F11  
 * 		3、(window.event.shiftKey && window.event.keyCode==121  //shift+F10
 * 		4、(window.event.altKey)&&(window.event.keyCode==115)	//alt+f4
 * 		5、67==window.event.keyCode			//屏蔽 ctrl+c 
 * 		6、68==window.event.keyCode			//屏蔽 ctrl+d 
 * 		7、83==window.event.keyCode			//屏蔽 ctrl+w 
 * 		8、86==window.event.keyCode			//屏蔽 ctrl+v
 * 		9、87==window.event.keyCode			//屏蔽 ctrl+s
 */

var event_gridid = "";
var event_key_isCTRL = false;
var event_key_isALT = false;
var event_key_isSHIFT = false;

document.onkeydown=function(event){
	var event = event || window.event;
	//对屏蔽的特殊按键进行处理
	var _keyCode = event.keyCode;
	
	if(event.ctrlKey){
		event_key_isCTRL = true;
	}
	if(event.altKey){
		event_key_isALT = true;
	}
	if (event.shiftKey){
		event_key_isSHIFT = true;
	}
	
	 //if (
	//			false
	//			||8 == window.event.keyCode 		//屏蔽Backspace
	//	     ){   
	//         window.event.keyCode=0;  
	//          window.event.returnValue=false;  
	//          return false;
	//	 }   
	 
//	if(_keyCode&&16!=_keyCode&&17!=_keyCode&&18!=_keyCode){
//		var _key = '';
//		if(event_key_isCTRL){
//			_key += 'ctrl';
//		}
//		if(event_key_isALT){
//			if(_key.length>0){
//				_key += '+';
//			}
//			_key += 'alt';
//		}
//		if(event_key_isSHIFT){
//			if(_key.length>0){
//				_key += '+';
//			}
//			_key += 'shift';
//		}
//		if(_key.length>0){
//			_key += '+';
//		}
//		switch(_keyCode){
//			case 112:
//				_key += 'f1';
//				break;
//			case 113:
//				_key += 'f2';
//				break;
//			case 114:
//				_key += 'f3';
//				break;
//			case 115:
//				_key += 'f4';
//				break;
//			case 116:
//				_key += 'f5';
//				break;
//			case 117:
//				_key += 'f6';
//				break;
//			case 118:
//				_key += 'f7';
//				break;
//			case 119:
//				_key += 'f8';
//				break;
//			case 120:
//				_key += 'f9';
//				break;
//			case 121:
//				_key += 'f10';
//				break;
//			case 122:
//				_key += 'f11';
//				break;
//			case 123:
//				_key += 'f12';
//				break;
//			case 27:
//				_key += 'esc';
//				break;
//			case 192:
//				_key += '`';
//				break;
//			case 189:
//				_key += '-';
//				break;
//			case 187:
//				_key += '=';
//				break;
//			case 8:
//				_key += 'back';
//				break;
//			case 9:
//				_key += 'tab';
//				break;
//			case 219:
//				_key += '[';
//				break;
//			case 221:
//				_key += ']';
//				break;
//			case 220:
//				_key += '\\';
//				break;
//			case 20:
//				_key += 'caps';
//				break;
//			case 186:
//				_key += ';';
//				break;
//			case 222:
//				_key += '\'';
//				break;
//			case 13:
//				_key += 'enter';
//				break;
//			case 188:
//				_key += ',';
//				break;
//			case 190:
//				_key += '.';
//				break;
//			case 191:
//				_key += '/';
//				break;
//			case 37:
//				_key += 'left';
//				break;
//			case 38:
//				_key += 'up';
//				break;
//			case 39:
//				_key += 'right';
//				break;
//			case 40:
//				_key += 'down';
//				break;
//			case 32:
//				_key += 'space';
//				break;
//			default:
//				_key += String.fromCharCode(_keyCode);
//				break;
//		}
//		$.keypress_call(_key);
//	}
	
	
	
	
//	
//	
//	 if (
//				false
//				||112 == window.event.keyCode 		//屏蔽 F1
//			//	||116 == window.event.keyCode 		//屏蔽 F5  
//				||122 == window.event.keyCode 		//屏蔽 F11  
//				||123 == window.event.keyCode 		//屏蔽 F12  
//		  		||(window.event.shiftKey && window.event.keyCode==121) 	//shift+F10  
//		     ){   
//	          window.event.keyCode=0;  
//	          window.event.returnValue=false;  
//	          return false;
//		 }   
//		if ((window.event.altKey)&&(window.event.keyCode==115)){   
//	         //屏蔽Alt+F4  
//			 window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");  
//			return false;
//		 }
//		 if((event.ctrlKey)
//				 &&(false
//					||67==event.keyCode				//屏蔽 ctrl+c 
//				//	||68==window.event.keyCode		//屏蔽 ctrl+d 
//				//	||83==window.event.keyCode		//屏蔽 ctrl+w 
//				//	||86==window.event.keyCode		//屏蔽 ctrl+v
//				//	||87==window.event.keyCode		//屏蔽 ctrl+s
//				)){
//			 	if(event_gridid){
//			 		var rows = $.grid_getSelections({
//						id:event_gridid
//					});
////			 		alert($.json2str(rows));
//			 		$.copy_to_clipboard('123123123');
////			 		 $.zclip({
////			 			   path:'js/lib/plugin/zclip/ZeroClipboard.swf',
////			 			   copy:'22233'
////			 		 });
//			 	}
//			 	
//			  event.keyCode=0;  
//	          event.returnValue=false;  
//	          return false;
//		 }
		 
};

//松开任何键，复原
document.onkeyup=function(event){
//	var event = event || window.event;
//	if(event.ctrlKey){
		event_key_isCTRL = false;
		event_key_isALT = false;
		event_key_isSHIFT = false;
//	}
};

/***************************************
 * 	string常用功能扩展
 **************************************/
//获取字符数组 
String.prototype.toCharArray=function(splitstr){ 
	if(!splitstr){
		splitstr = ',';
	}
	return this.split(splitstr); 
};
//获取N个相同的字符串 
String.prototype.repeat=function(num){ 
    var tmpArr=[]; 
    for(var i=0;i<num;i++){
    	tmpArr.push(this);
    }
    return tmpArr.join(""); 
};
//逆序 
String.prototype.toReverse=function(){ 
	return this.split("").reverse().join(""); 
};
//测试是否是数字 
String.prototype.isNumber=function(){ 
    var tmpFloat=parseFloat(this); 
    if(isNaN(tmpFloat)){
    	return false;
    }
    var tmpLen=this.length-tmpFloat.toString().length; 
    return tmpFloat+"0".Repeat(tmpLen)==this; 
};
//测试是否是整数 
String.prototype.isInt=function(){ 
    if(this=="NaN"){
    	return false;
    }
    return this==parseInt(this).toString(); 
};
// 合并多个空白为一个空白 
String.prototype.resetBlank = function(){ 
	return this.replace(/\s+/g," ");
};
// 除去左边空白 
String.prototype.ltrim = function(){ 
	return this.replace(/^\s+/g,"");  
};
// 除去右边空白 
String.prototype.rtrim = function(){ 
	return this.replace(/\s+$/g,"");  
};
// 除去两边空白 
String.prototype.trim = function(){ 
    return this.replace(/(^\s+)|(\s+$)/g,"");  
};
// 保留数字 
String.prototype.getNumber = function(){ 
    return this.replace(/[^\d]/g,""); 
};
// 保留字母 
String.prototype.getEN = function(){ 
    return this.replace(/[^A-Za-z]/g,"");  
};
// 保留中文 
String.prototype.getCN = function(){ 
    return this.replace(/[^\u4e00-\u9fa5\uf900-\ufa2d]/g,""); 
};
// 得到字节长度 
String.prototype.getRealLength = function(){ 
    return this.replace(/[^\x00-\xff]/g,"--").length; 
};
// 从左截取指定长度的字串 
String.prototype.left = function(n){ 
    return this.slice(0,n); 
};
// 从右截取指定长度的字串 
String.prototype.right = function(n){
    return this.slice(this.length-n); 
};


// Unicode转化 
String.prototype.ascW = function(){ 
    var strText = ""; 
    for (var i=0; i<this.length; i++) strText += "&#" + this.charCodeAt(i) + ";"; 
    return strText; 
};

//HTML编码 
String.prototype.HTMLEncode = function(){ 
	var _REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
	
	var res = this.replace(
							_REGX_HTML_ENCODE,
							function($0){
									var c = $0.charCodeAt(0), r = ["&#"];
									c = (c == 0x20) ? 0xA0 : c;
									r.push(c); r.push(";");
									return r.join("");
							});
    return res; 
};

//HTML反编码 
String.prototype.HTMLDecode = function(){
	var _REGX_HTML_DECODE =  /&\w+;|&#(\d+);/g;
	var _HTML_DECODE = {
	        "&lt;" : "<", 
	        "&gt;" : ">", 
	        "&amp;" : "&", 
	        "&nbsp;": " ", 
	        "&quot;": "\"", 
	        "&copy;": ""

	        // Add more
	    };
	
	var res = this.replace(
							_REGX_HTML_DECODE,
							function($0,$1){
				                  var c = _HTML_DECODE[$0]; // 尝试查表
				                  if(c === undefined){
				                      // Maybe is Entity Number
				                      if(!isNaN($1)){
				                          c = String.fromCharCode(($1 == 160) ? 32 : $1);
				                      }else{
				                          // Not Entity Number
				                          c = $0;
				                      }
				                  }
			                  return c;
			              });
	return res;
};

/************************************
 * 		处理自定义控件
 ************************************/
$(document).ready(function(){
	//创建grid右键菜单
	$("body").append('<div id="_ID_grid_contextmenu" keepshow="true" class="easyui-menu" style="width:120px;"></div>');
	
//	//全局事件
//	$(".layout").bind("click",function(event){
//	});
//
//	//替换inputpop控件
//	$(".wdk_inputpop").each(function(){
//		var _width = this.clientWidth;
//		var _height = this.clientHeight;
//		var _id = this.id;
//		var _name = this.name;
//		var _value = this.value;
//		var _required = $(this).attr('isrequired');
//		var _hidevalue = $(this).attr('hidevalue');
//		var _options = $(this).attr('data-options');
//		_options = _options.replace(/\'/ig,"\\\'").replace(/\"/ig,"\\\'");
//		
//		var _class = 'inputpop_input';
//		if(!_value&&'true'==_required){
//			_class = 'inputpop_input_required';
//		}
//		
//		var cstr = '<span class="inputpop_span" id="inputpop_span_'+_id+'" style="width:'+_width+'px;height:'+_height+'px;">'
//			+'			<input class="'+_class+'" id="'+_id+'" '
//			+'					name="'+_name+'" isrequired="'+_required+'" value="'+_value+'" '
//			+'					onfocusin="_inputpop_onfocusin(\''+_id+'\')" '
//			+'					onfocusout="_inputpop_onfocusout(\''+_id+'\')" '
//			+'					onfocus="this.select();" '
//			+'					style="width:'+(_width-25)+'px;height:'+_height+'px;line-height:'+_height+'px;" type="text" autocomplete="off"/>'
//			+'			<span class="inputpop_arrow_span">'
//			+'				<span class="inputpop_arrow" style="height: 20px;" onclick="_inputpop_openwin(\'{'+_options+'}\')"/>'
//			+'			</span>'
//			+'			<input class="inputpop_hidden_name" id="inputpop_hidden_hidevalue_'+_id+'" type="hidden" value="'+_hidevalue+'"/>'
//			+'			<input class="inputpop_hidden_value" id="inputpop_hidden_value_'+_id+'" type="hidden" value="'+_value+'"/>'
//			+'		</span>';
//		this.outerHTML = cstr;
//	});

});

/************************************
 * 针对datebox的自定义扩展
 ************************************/
/**
 * linkbutton方法扩展
 * @param {Object} jq
 */
$.extend($.fn.linkbutton.methods, {
    /**
     * 激活选项（覆盖重写）
     * @param {Object} jq
     */
    enable: function(jq){
        return jq.each(function(){
            var state = $.data(this, 'linkbutton');
            if ($(this).hasClass('l-btn-disabled')) {
                var itemData = state._eventsStore;
                //恢复超链接
                if (itemData.href) {
                    $(this).attr("href", itemData.href);
                }
                //回复点击事件
                if (itemData.onclicks) {
                    for (var j = 0; j < itemData.onclicks.length; j++) {
                        $(this).bind('click', itemData.onclicks[j]);
                    }
                }
                //设置target为null，清空存储的事件处理程序
                itemData.target = null;
                itemData.onclicks = [];
                $(this).removeClass('l-btn-disabled');
            }
        });
    },
    /**
     * 禁用选项（覆盖重写）
     * @param {Object} jq
     */
    disable: function(jq){
        return jq.each(function(){
            var state = $.data(this, 'linkbutton');
             
            if (!state._eventsStore)
                state._eventsStore = {};
            if (!$(this).hasClass('l-btn-disabled')) {
                var eventsStore = {};
                eventsStore.target = this;
                eventsStore.onclicks = [];
                //处理超链接
                var strHref = $(this).attr("href");
                if (strHref) {
                    eventsStore.href = strHref;
                    $(this).attr("href", "javascript:void(0)");
                }
                //处理直接耦合绑定到onclick属性上的事件
                var onclickStr = $(this).attr("onclick");
                if (onclickStr && onclickStr != "") {
                    eventsStore.onclicks[eventsStore.onclicks.length] = new Function(onclickStr);
                    $(this).attr("onclick", "");
                }
                //处理使用jquery绑定的事件
                var eventDatas = $(this).data("events") || $._data(this, 'events');
                if (eventDatas["click"]) {
                    var eventData = eventDatas["click"];
                    for (var i = 0; i < eventData.length; i++) {
                        if (eventData[i].namespace != "menu") {
                            eventsStore.onclicks[eventsStore.onclicks.length] = eventData[i]["handler"];
                            $(this).unbind('click', eventData[i]["handler"]);
                            i--;
                        }
                    }
                }
                state._eventsStore = eventsStore;
                $(this).addClass('l-btn-disabled');
            }
        });
    }
});

/************************************
 * 针对validatebox的自定义扩展，扩展validType
 ************************************/
$.extend($.fn.validatebox.defaults.rules, {
		//自定义验证规则
		regular : {
		    validator : function (value, param) {
				if(""==value){
	    			return true;
	    		}
				if(!param){
					return true;
				}else{
					var _fun = window[param];
					var res = _fun(value);
					if(true!=res){
						$.fn.validatebox.defaults.rules.regular.message = res;
						return false;
					}else{
						return true;
					}
				}
		    },
		    message : ''
		}, 
		isNULL : {
	        validator : function (value, param) {
	    		if (value){
	    			return true;
	    		}else{
	    			return false;
	    		}
	        },
	        message:'不能为空'
	    },
		//输入长度限制
		length : {
	        validator : function (value, param) {
	           if(!value){
	        	   return false;
	           }else{
	        	   if(value.length>param[1]||value.length<param[0]){
	        		   return false;
	        	   }else{
	        		   return true;
	        	   }
	           }
	        },
	        message : '内容长度应该介于{0}和{1}之间'
		},
		 //小数点位数
	    number:{
	    	 validator : function (value, param) {
				var _n2 = param[1];			//小数位数
				var _n1 = param[0]-_n2;		//整数位数
				
				var pattern = new RegExp('^\\d{0,'+_n1+'}[.]{0,1}\\d{0,'+_n2+'}$','gi');
				
	    		if (pattern.test(value)){
	    			return true;
	    		}else{
	    			return false;
	    		}
	    		
	    		
	        },
	        message:'数字格式不正确'
	    },
	    
		//最短长度
	    minLength : {
	        validator : function (value, param) {
				if(!value){
		        	   return false;
		           }else{
		        	   if(value.length<param){
		        		   return false;
		        	   }else{
		        		   return true;
		        	   }
		           }
	        },
	        message : '内容长度应该不小于{0}'
	    },
	    //最大长度
	    maxLength : {
	    	validator : function (value, param) {
				if(!value){
		        	   return false;
		           }else{
		        	   if(value.length>param){
		        		   return false;
		        	   }else{
		        		   return true;
		        	   }
		           }
	        },
	        message : '内容长度应该不大于{0}'
	    },
	    //是否中文
	    isCN : {
	        validator : function (value, param) {
	    		//如果值为空，通过校验 
	    		if(""==value){
	    			return true;
	    		}
	    		var pattern = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi;   
	    		if(pattern.test(value)){   
	    			return true;   
	    		}else{
	    			return false;
	    		}
	        },
	        message:'内容包含非中文字符'
	    },
	    //是否是整数，包含负数
	    isNumber : {
	        validator : function (value, param) {
	    		var pattern=/^(\-?)(\d+)$/gi; 
	    		if (pattern.test(value)){
	    			return true;
	    		}else{
	    			return false;
	    		}
	        },
	        message:'非整数'
	    },
	    //是否是小数，包含负数
	    isFloat : {
	        validator : function (value, param) {
	    		var pattern = /^(\-?)(\d+)(.{1})(\d+)$/g; 
	    		if (pattern.test(value)){
	    			return true;
	    		}else{
	    			return false;
	    		}
	        },
	        message:'非小数'
	    },
	    //是否是普通电话
	    isTel : {
		        validator : function (value, param) {
		    		var pattern = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; 
		    		if (pattern.test(value)){
		    			return true;
		    		}else{
		    			return false;
		    		}
		        },
		        message:'请输入正确的普通电话格式'
		},
	    //是否是移动
	    isMobile : {
		        validator : function (value, param) {
		    		var pattern = /^1[3|4|5|8][0-9]\d{8}$/; 
		    		if (pattern.test(value)){
		    			return true;
		    		}else{
		    			return false;
		    		}
		        },
		        message:'请输入正确的移动电话格式'
		},
		//是否是合法的URL地址
	    isURL : {
		        validator : function (value, param) {
		    		var pattern = /^[a-zA-z]+:\/\/[^s]*$/; 
		    		if (pattern.test(value)){
		    			return true;
		    		}else{
		    			return false;
		    		}
		        },
		        message:'请输入正确的URL地址'
		},
		//是否是合法的邮政编码
	    isPostCode : {
		        validator : function (value, param) {
		    		var pattern = /^([0-9]{3})+.([0-9]{4})+$/; 
		    		if (pattern.test(value)){
		    			return true;
		    		}else{
		    			return false;
		    		}
		        },
		        message:'请输入正确的邮政编码'
		},
		//是否是合法的IP
	    isIP : {
		        validator : function (value, param) {
		    		var pattern = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/; 
		    		if (pattern.test(value)){
		    			return true;
		    		}else{
		    			return false;
		    		}
		        },
		        message:'请输入正确的IP'
		}
	});
/************************************
 * 针对tab的自定义扩展，扩展新增setTabTitle方法
 ************************************/
$.extend($.fn.tabs.methods, {
    setTabTitle:function(jq,opts){
	    return jq.each(function(){
	        var tab = opts.tab;
	        var options = tab.panel("options");
	        var tab = options.tab;
	        options.title = opts.title;
	        var title = tab.find("span.tabs-title");
	        title.html(opts.title);
	    });
	},
	/**
	 * 绑定双击事件
	 * @param {Object} jq
	 * @param {Object} caller 绑定的事件处理程序
	 */
	bindDblclick: function(jq, caller){
	    return jq.each(function(){
	        var that = this;
	        $(this).children("div.tabs-header").find("ul.tabs").undelegate('li', 'dblclick.tabs').delegate('li', 'dblclick.tabs', function(e){
	            if (caller && typeof(caller) == 'function') {
	                var title = $(this).text();
	                var index = $(that).tabs('getTabIndex', $(that).tabs('getTab', title));
	                caller(index, title);
	            }
	        });
	    });
	},
	/**
	 * 解除绑定双击事件
	 * @param {Object} jq
	 */
	unbindDblclick: function(jq){
	    return jq.each(function(){
	        $(this).children("div.tabs-header").find("ul.tabs").undelegate('li', 'dblclick.tabs');
	    });
	}
});


/************************************
 * 针对datagrid的自定义扩展
 ************************************/
$.extend($.fn.datagrid.methods, {
	    addEditor : function(jq, param) {
	        if (param instanceof Array) {
	            $.each(param, function(index, item) {
	                var e = $(jq).datagrid('getColumnOption', item.field);
	                e.editor = item.editor;
	            });
	        } else {
	            var e = $(jq).datagrid('getColumnOption', param.field);
	            e.editor = param.editor;
	        }
	    },
	    removeEditor : function(jq, param) {
	        if (param instanceof Array) {
	            $.each(param, function(index, item) {
	                var e = $(jq).datagrid('getColumnOption', item);
	                e.editor = {};
	            });
	        } else {
	            var e = $(jq).datagrid('getColumnOption', param);
	            e.editor = {};
	        }
	    },
	    keyHandler:function(jq){
	    	return jq.each(function () {
	            var grid = $(this);
	            grid.datagrid('getPanel').panel('panel').attr('tabindex', 1).bind('keydown', function (event) {
	            	//对屏蔽的特殊按键进行处理
	            	var _keyCode = event.which;
	            	var _key = '';

	            	var isCtrl = false;
	            	var isAlt = false;
	            	var isShift = false;
	            	if(event.ctrlKey){
	            		isCtrl = true;
	            	}
	            	if(event.altKey){
	            		isAlt = true;
	            	}
	            	if (event.shiftKey){
	            		isShift = true;
	            	}
	            	if(_keyCode&&16!=_keyCode&&17!=_keyCode&&18!=_keyCode){
	            		if(isCtrl){
	            			_key += 'ctrl';
	            		}
	            		if(isAlt){
	            			if(_key.length>0){
	            				_key += '_';
	            			}
	            			_key += 'alt';
	            		}
	            		if(isShift){
	            			if(_key.length>0){
	            				_key += '_';
	            			}
	            			_key += 'shift';
	            		}
	            		if(_key.length>0){
	            			_key += '_';
	            		}
	            		switch(_keyCode){
	            			case 112:_key += 'f1';break;
	            			case 113:_key += 'f2';break;
	            			case 114:_key += 'f3';break;
	            			case 115:_key += 'f4';break;
	            			case 116:_key += 'f5';break;
	            			case 117:_key += 'f6';break;
	            			case 118:_key += 'f7';break;
	            			case 119:_key += 'f8';break;
	            			case 120:_key += 'f9';break;
	            			case 121:_key += 'f10';break;
	            			case 122:_key += 'f11';break;
	            			case 123:_key += 'f12';break;
	            			case 27:_key += 'esc';break;
	            			case 192:_key += '`';break;
	            			case 189:_key += '-';break;
	            			case 187:_key += '=';break;
	            			case 8:_key += 'back';break;
	            			case 9:_key += 'tab';break;
	            			case 219:_key += '[';break;
	            			case 221:_key += ']';break;
	            			case 220:_key += '\\';break;
	            			case 20:_key += 'caps';break;
	            			case 186:_key += ';';break;
	            			case 222:_key += '\'';break;
	            			case 13:_key += 'enter';break;
	            			case 188:_key += ',';break;
	            			case 190:_key += '.';break;
	            			case 191:_key += '/';break;
	            			case 37:_key += 'left';break;
	            			case 38:_key += 'up';break;
	            			case 39:_key += 'right';break;
	            			case 40:_key += 'down';break;
	            			case 32:_key += 'space';break;
	            			default:_key += String.fromCharCode(_keyCode).toLowerCase();break;
	            		}
	            	}
	            	var _keyParam = new Object();
	            	var _options = grid.datagrid('options');
	            	_keyParam.options = _options;
	            	_keyParam.row = $.grid_getSelected({id:_options.gridid});
	            	
	            	var _rowIndex = -1;
	            	var selected = grid.datagrid('getSelected');
	               	if (selected) {
	               		_rowIndex = grid.datagrid('getRowIndex', selected);
	               	}
	            	_keyParam.rowIndex = _rowIndex+'';
	            	
	            	var _keyHandler = _options.keyHandler;
	            	for(var keyStr in _keyHandler){
	            		if(_key==keyStr){
	            			var _fun = _keyHandler[keyStr];
	            			_fun = $.event_getHandler(_fun);
	            			_fun(_keyParam);
	            		}
	            	}
	            	//阻止事件传递
	            	event.stopPropagation();  
	            	
	            });
	        });
	    },
	    keyCtr : function (jq) {
	        return jq.each(function () {
	            var grid = $(this);
	            grid.datagrid('getPanel').panel('panel').attr('tabindex', 1).bind('keydown', function (e) {
	            	var _start = 0;
	            	var _rows = grid.datagrid('getRows').length;
	            	var _end = _start + _rows -1;
	            	var _pag = grid.datagrid('getPager').data("pagination");
	            	if(_pag){
		            	var options = _pag.options;  
		            	var pagenum = options.pageNumber;  
		            	var pagesize = options.pageSize;
		            	_start = (pagenum-1)*pagesize;
		            	_end = _start + _rows -1;
	            	}
	            	
	                switch (e.keyCode) {
	                case 38: // up
	                    var selected = grid.datagrid('getSelected');
	                    if (selected) {
	                        var index = grid.datagrid('getRowIndex', selected);
	                        grid.datagrid('selectRow', index - 1);
	                    } else {
	                        
	                        grid.datagrid('selectRow', rows.length - 1);
	                    }
	                    break;
	                case 40: // down
	                    var selected = grid.datagrid('getSelected');
	                    if (selected) {
	                        var index = grid.datagrid('getRowIndex', selected);
	                        grid.datagrid('selectRow', index + 1);
	                    } else {
	                        grid.datagrid('selectRow', 0);
	                    }
	                    break;
	                }
	            });
	        });
	    }
	});

//扩展datagrid的editor方法以适应可编辑grid的功能要求
$.extend($.fn.datagrid.defaults.editors, {
	checkbox:{
		init: function(container, options){ 
			
			//处理事件定义
			var _onCheck = function(){};
			if(null!=options){
				_onCheck = options.onCheck;
			}
			var _hadnler_onCheck = $.event_getHandler(_onCheck);
			
			var cstr = '<input type="checkbox" id="selfchk" onclick="grid_checkbox_onCheck(this,'+_hadnler_onCheck+')">';// param="'+strParam+'"  grid_checkbox_onClick(this,\''+jsonstr+'\')
			var input = $(cstr).appendTo(container);
			return input;
		}, 
		getValue: function(target){
			var ochk = $(target).parent().find('input#selfchk');
			var cstr = '<input type="checkbox"  style="align:center" checked disabled >';
			if(ochk.prop('checked')){
				cstr = '<input type="checkbox"  style="align:center" checked disabled >';
			}else{
				cstr = '<input type="checkbox"  style="align:center" disabled >';
			}
			return cstr;
		}, 
		setValue: function(target, value){
			var ochk = $(target).parent().find('input#selfchk');
			if('1'==value){
				ochk.prop('checked',true);
			}else if('0'==value){
				ochk.prop('checked',false);
			}else{
				var ov = $(value);
				if(ov.prop('checked')){
					ochk.prop('checked',true);
				}else{
					ochk.prop('checked',false);
				}
			}
		}, 
		resize: function(target, width){ var input = $(target); if ($.boxModel == true){ input.width(width - (input.outerWidth() - input.width())); } else { input.width(width); } } 
	},
	datetimebox: {//datetimebox就是你要自定义editor的名称
		init: function(container, options){ 
					var input = $('<input class="easyuidatetimebox" style="width:50px;">').appendTo(container); 
					return input.datetimebox({formatter:function(date){ return new Date(date).format("yyyy-MM-dd hh:mm:ss"); }}); 
				}, 
		getValue: function(target){ return $(target).parent().find('input.combo-value').val(); }, 
		setValue: function(target, value){ $(target).datetimebox("setValue",value); }, 
		resize: function(target, width){ var input = $(target); if ($.boxModel == true){ input.width(width - (input.outerWidth() - input.width())); } else { input.width(width); } } 
	},
	//输入弹出框，grid的可编辑单元格的类型
	inputpop:{
		init:function(container, options){
			try{
				var methodid = $.method_reg(window,'_callback_inputpop_openwin_grid',{container:container});
				var _url = options.url;
				var _type = options.type;
				var _editable = options.editable;
				var _keyHandler = options.keyHandler;
				
				var _onBeforeOpen_mid = '';		//(null==_onBeforeOpen)?'':$.method_reg(window,_onBeforeOpen);
				var _callback_mid = '';			//(null==_callback)?'':$.method_reg(window,_callback);
				var _onChangeValue_mid = '';
//				var _onClick_mid = '';
//				var _onKeyPress_mid = '';
//				var _onKeyUp_mid = '';
//				var _onKeyDown_mid = '';
				
				var _onChangeValue = options.onChangeValue;
				if(_onChangeValue){
					if('string'==typeof(_onChangeValue)&&_onChangeValue.length==32){
						_onChangeValue_mid = _onChangeValue;
					}else{
						_onChangeValue = $.event_getHandler(_onChangeValue);
						_onChangeValue_mid = $.method_reg(window,_onChangeValue);
					}
				}else{
					_onChangeValue = null;
					_onChangeValue_mid = '';
				}
				
				
				var _onBeforeOpen = options.onBeforeOpen;
				if(_onBeforeOpen){
					if('string'==typeof(_onBeforeOpen)&&_onBeforeOpen.length==32){
						_onBeforeOpen_mid = _onBeforeOpen;
					}else{
						_onBeforeOpen = $.event_getHandler(options.onBeforeOpen);
						_onBeforeOpen_mid = $.method_reg(window,_onBeforeOpen);
					}
				}else{
					_onBeforeOpen = null;
					_onBeforeOpen_mid = '';
				}
					
				var _callback = options.callback;
				if(_callback){
					if('string'==typeof(_callback)&&_callback.length==32){
						_callback_mid = _callback;
					}else{
						_callback = $.event_getHandler(options.callback);
						_callback_mid = $.method_reg(window,_callback);
					}
				}else{
					_callback = null;
					_callback_mid = '';
				}
				
				
				var _keyHandler_new = new Object();
				for(var shortkey in _keyHandler){
					var _handler = _keyHandler[shortkey];
					var _handler_mid = "";
					if(_handler){
						if('string'==typeof(_handler)&&_handler.length==32){
							_handler_mid = _handler;
						}else{
							_handler = $.event_getHandler(_handler);
							_handler_mid = $.method_reg(window,_handler);
						}
					}else{
						_handler = null;
						_handler_mid = '';
					}
					var ks = shortkey+'';
					_keyHandler_new[ks] = _handler_mid;
				}
				
				options.onBeforeOpen = _onBeforeOpen_mid;
				options.callback = _callback_mid;
				options.onChangeValue = _onChangeValue_mid;
				options.keyHandler = _keyHandler_new;
				
				
				var _readonly = ('false'==_editable||false==_editable)?'readonly ':' ';
				
				//自适应容器宽度
				var _width = 0;
				var w = $(container).css("width");
				var nw = w.replace("px","");
				_width = parseInt(nw);
				
				var css_arrow = 'inputpop_arrow';
				switch(_type){
					case 'datetime':
						css_arrow = 'inputpop_arrow_date';
						options.url = WDK_ROOT+'/module/public/inputpop_datetime.jsp';
						break;
					case 'date':
						css_arrow = 'inputpop_arrow_date';
						options.url = WDK_ROOT+'/module/public/inputpop_date.jsp';
						break;
					case 'select':
						options.url = WDK_ROOT+'/module/public/inputpop_select.jsp';
						break;
					case 'tree':
						options.url = WDK_ROOT+'/module/public/inputpop_tree.jsp';
						break;
					case 'treegrid':
						options.url = WDK_ROOT+'/module/public/inputpop_treegrid.jsp';
						break;
					case 'grid':
						options.url = WDK_ROOT+'/module/public/inputpop_grid.jsp';
						break;
					case 'week':
						options.url = WDK_ROOT+'/module/public/inputpop_week.jsp';
						break;
					default:
						break;
				}
				//传递的参数
				var jsonstr = $.json2str(options);
				jsonstr = jsonstr.replace(/\'/ig,"\\\'").replace(/\"/ig,"\\\'");
				var cstr = '<span class="inputpop_span" style="height:38px;">'
					+'			<input class="inputpop_input" '+_readonly+' style="width:'+(_width-30)+'px;height: 38px; line-height: 38px;"  onkeyDown="_inputpop_onkeydown_grid(this,event,\''+methodid+'\',\''+jsonstr+'\')" type="text" autocomplete="off"  />'
					+'			<span class="inputpop_arrow_span">'
					+'				<span id="inputpop_arrow_click" class="'+css_arrow+'" style="height: 38px;" onclick="_inputpop_openwin_grid(this,\''+methodid+'\',\''+jsonstr+'\')"/>'
					+'			</span>'
					+'			<input class="inputpop_hidden_options" type="hidden" value="'+jsonstr+'"/>'
			//		+'			<input class="inputpop_hidden_name" type="hidden" value="2013-10-30 15:43:25"/>'
			//		+'			<input class="inputpop_hidden_value" type="hidden" value="2013-10-30 15:43:25"/>'
					+'		</span>';
				var input = $(cstr).appendTo(container); 

				return input;
			}catch(e){
//				alert(e.message);
				$.getRoot().$.messager.alert('信息提示','表格编辑错误：'+e.message,'error');
			}
		},
		getValue: function(target){ 
			var showValue = $(target).parent().find('input.inputpop_input').val();
		//	var hiddenValueName = $(target).parent().find('input.inputpop_hidden_name').val();
		//	var hiddenValueValue = $(target).parent().find('input.inputpop_hidden_value').val();
			//如果显示值和隐藏值不一致，说明是人工输入，则以人工输入为准
		//	alert('getValue showValue='+showValue+"   hiddenValueValue="+hiddenValueValue+"   hiddenValueName="+hiddenValueName)
		//	if(showValue!=hiddenValueValue){
		//		hiddenValueValue = showValue;
		//		hiddenValueName = showValue;
		//	}else{
				//否则是选择
		//		showValue = hiddenValueName;
		//	}
		//	var res = showValue+'<input type=hidden value="'+hiddenValueName+'|||'+hiddenValueValue+'">';
		//	alert('getValue  res='+res);
			return showValue; 
		}, 
		setValue: function(target, value){
		/*	var options = $(target).parent().find('input.inputpop_hidden_options').val();
			options = options.replace(/\\\'/ig,"\'");
			var joptions = $.str2json(options);
			var selectedrow = $("#"+joptions.gridid).datagrid("getSelected");
			
			var showValue;
			var hiddenValueName;
			var hiddenValueValue;
			if(value&&-1!=value.indexOf("<")){
				//如果是选择之后再点击，则按照新的来
				showValue = value.substring(0,value.indexOf("<"));
				var inputHTML = value.substring(value.indexOf("<"),value.length);
				hiddenValueName = $(inputHTML).val().split('|||')[0];
				hiddenValueValue = $(inputHTML).val().split('|||')[1];
			}else{
				//按照默认配置的值来
				var initshowfield = joptions.initshowfield;
				var inithiddenfield = joptions.inithiddenfield;
				if(initshowfield&&inithiddenfield){
					showValue = selectedrow[initshowfield];
					hiddenValueName = selectedrow[initshowfield];
					hiddenValueValue = selectedrow[inithiddenfield];
				}else{
					showValue = value;
					hiddenValueName = value;
					hiddenValueValue = value;
				}
			}
			*/
		//	$(target).val(hiddenValueValue);
		//	alert('setValue value='+value+'    hiddenValueValue='+hiddenValueValue+'   hiddenValueName='+hiddenValueName);
			$(target).parent().find('input.inputpop_input').val(value); 
		//	$(target).parent().find('input.inputpop_hidden_name').val(hiddenValueName); 
		//	$(target).parent().find('input.inputpop_hidden_value').val(hiddenValueValue); 
		//	alert('setvalue value='+value+' \n  showValue='+showValue+'    hiddenValueName='+hiddenValueName+'    hiddenValueValue='+hiddenValueValue);
		}, 
		resize: function(target, width){ var input = $(target); if ($.boxModel == true){ input.width(width - (input.outerWidth() - input.width())); } else { input.width(width); } },
		keyup:function(){alert(222);}

	}
});



//格式化
function _grid_formatter(value, row, index){
	if(row.dataformat){
		//alert(row.fieldcode);
	}
	if(value){
		return value+'<input type="hidden" value="hidden_'+value+'" >';
	}else{
		return '';
	}
}
function _defaultFormat(value, row, index){
	return value;
}

//返回格式化函数字符串
function _getFormat(dataformat){
	try{
		if(eval(dataformat)){
			//alert('函数存在' )
		}else{
			//alert('函数不存在')
		}
	}catch(e){
		return '_defaultFormat';
	}
//	
//	switch(dataformat){
//		case 'yyyy':
//			return '_format_yyyy';
//		default:						//自定义过滤器
	return dataformat;
//	}
}

/**
 * 如果为编辑列，则修改当前列样式
 * @param value
 * @param rowData
 * @param rowIndex
 * @return
 */
function grid_colsytle_editor(value,rowData,rowIndex){
	return 'background-color:#ccc;color:white;';
}

//公用显示格式转换
function date_yyyy(value, row, index){
	var datestr = "";
	if(null!=value&&""!=value.trim()){
		datestr = new DateUtil().formateDate('yyyy',value);
	}
	return datestr;
}
function date_yyyyMM(value, row, index){
	var datestr = "";
	if(null!=value&&""!=value.trim()){
		datestr = new DateUtil().formateDate('yyyy-MM',value);
	}
	return datestr;
}
function date_yyyyMMdd(value, row, index){
	var datestr = "";
	if(null!=value&&""!=value.trim()){
		datestr = new DateUtil().formateDate('yyyy-MM-dd',value);
	}
	return datestr;
}
function date_yyyyMMddHHmmss(value, row, index){
	var datestr = "";
	if(null!=value&&""!=value.trim()){
		datestr = new DateUtil().formateDateTime('yyyy-MM-dd HH:mm:ss',value);
	}
	return datestr;
}


function _sort_number(a,b){
	var number1 = parseFloat(a);  
	var number2 = parseFloat(b);  
	return (number1 > number2 ? 1 : -1);    
}  

/** 针对datagrid的自定义扩展   end *********/






/************************************
 * 		核心工具类
 ************************************/
$.extend({
	
	/*********************************************
	 * 					基础工具方法
	 * 	函数说明：
	 * 		1、getURLParams：获取url地址栏后的参数合集，返回object
	 * 		2、getURLParam：根据name获取url地址栏后的指定参数
	 * 		3、getFuncName：获取function的名称
	 * 		3、createXMLHttpRequest：内部使用，创建ajax访问对象
	 * 		4、cuajax：基于jquery的ajax提交方法
	 * 		5、getDateTime：获取当前日期，格式为yyyy-MM-dd HH:mm:ss
	 * 		6、getID：获取唯一UUID
	 * 		7、isNumber：判断是否为小数
	 * 		8、getAbsolutePos:获取html元素的绝对位置
	 * 		9、json2str：将json对象转换为string字符串
	 * 		10、str2json：将string字符串转换为json对象
	 * 		11、getRoot：获取最顶层对象对象
	 * 		12、showDialog：打开dialog对话框
	 * 		13、openWin：打开弹出页面，调用最顶层对象的该方法
	 * 		14、closeWin：关闭弹出页面，调用最顶层对象的该方法
	 * 		15、method_reg：注册方法，事件通讯，通过最顶层对象实现
	 * 		16、method_call：调用方法，事件通讯，通过最顶层对象实现
	 * 		17、method_remove：删除方法，事件通讯，通过最顶层对象实现
	 */
	
	getIEVersion:function(){
		var ua = navigator.userAgent;
		var s = "MSIE";
		var version = 0;
		var i;
		var isIE = false;
		if ((i = ua.indexOf(s)) >= 0) {
			isIE = true;
			version = parseFloat(ua.substr(i + s.length));
		}
		return version;
	},
	//基础提示方法
	alt:function(desc,detail,title,atype){
		var _wid = $.getUUID();
		title = title?title:'信息提示';
		detail = detail?detail:'';
		$.getRoot().openAlert({
			id:_wid,
			title:title,
			desc:desc,
			detail:detail,
			atype:atype,
			height:300,
			width:400,
			modal:true
		});
	},
	alert:function(desc,detail,title){
		$.alt(desc,detail,title,'');
	},
	warn:function(desc,detail,title){
		$.alt(desc,detail,title,'warning');
	},
	error:function(desc,detail,title){
		$.alt(desc,detail,title,'error');
	},
	info:function(desc,detail,title){
		$.alt(desc,detail,title,'info');
	},
	question:function(desc,detail,title){
		$.alt(desc,detail,title,'question');
	},
	getURLParams: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++){
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		var _urlid = vars['ipturlid'];
		if(null!=_urlid&&""!=_urlid){
			var pobj = $.getRoot()._INPUTPOP[_urlid];
			if(null!=pobj){
				for(var att in pobj){
					vars[att] = pobj[att];
				}
			}
		}
		return vars;
	},
	getURLParam: function(name){
		return $.getURLParams()[name];
	},
	//获取function的名称
	getFuncName:function(_callee) {
		var _text = _callee.toString();
		var _scriptArr = document.scripts;
		for (var i=0; i<_scriptArr.length; i++) {
			var _start = _scriptArr[i].text.indexOf(_text);
			if (_start != -1) {
				if (/^function\s*\(.*\).*/.test(_text)) {
					//if (/^function\s*\(.*\).*\r\n/.test(_text)) {
					var _tempArr = _scriptArr[ i].text.substr(0, _start).split('\r\n'); 
					return _tempArr[_tempArr.length - 1].replace(/(var)(\s*)/g, '').replace(/=/g, '');
				} else {
					return _text.match(/^function\s*([^\(]+).*/)[1];
					//return _text.match(/^function\s*([^\(]+).*\r\n/)[1];
				}
			}
		}
	},
//	function _handler_grid_export2excel_template(gridcode,gridid){

	//创建ajax传输对象
	createXMLHttpRequest:function() {  
		var request = false;  
		if (window.XMLHttpRequest) {  
			request = new XMLHttpRequest();  
			if (request.overrideMimeType) {  
				request.overrideMimeType('text/xml');  
			}  
		} else if (window.ActiveXObject) {  
			var versions = [ 'Microsoft.XMLHTTP', 'MSXML.XMLHTTP',  
					'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0',  
					'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0',  
					'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP' ];  
			for ( var i = 0; i < versions.length; i++) {  
				try {  
					request = new ActiveXObject(versions[i]);  
					if (request) {  
						return request;  
					}  
				} catch (e) {  
				}  
			}  
		}  
		return request;  
	},
	//提交ajax
	cuajax:function(jparam){
		try{
			var _url = jparam["url"];					//目标地址
			var _method = jparam["method"];				//提交方式，get或者post				
			var _data = jparam["data"];					//提交的参数
			var _timeout = jparam["timeout"];			//超时时间
			var _ontimeout = jparam["onTimeout"];		//超时回调
			var _success = jparam["success"];			//成功
			var _error = jparam["error"];				//失败
			
			var _param = "";			//提交的参数
			var _tm;					//超时对象
			var _xmlhttp;

			//读取提交参数
			var paramarr = new Array();
			/*
			if(null!=_data&&_data.length>0){
				$.each(_data,function(){
					paramarr.push(this.name+"="+this.value);
				});
			}
			*/
			if(_data){
				for(var att in _data){
					//paramarr.push(att+"="+_data[att]);
					var str = _data[att]+'';
					str = str.replace(/\+/g,"%2B");
					paramarr.push(att+"="+str);
				}
			}
			_param = paramarr.join('&');

			//设置默认值
			_method = (null==_method||""==_method||"get"!=_method.toLowerCase())?"post":"get";
			_timeout = (null==_timeout||""==_timeout)?30*000:_timeout;

			//进行ajax提交
			if(null!=_url&&""!=_url){
				_url += _url.match(/\?/) ? (_url.match(/\=/)?"&ajaxparamtime="+new Date().getTime():"ajaxparamtime="+new Date().getTime()) : ("?ajaxparam="+new Date().getTime());
					_xmlhttp = $.createXMLHttpRequest();
					_xmlhttp.onreadystatechange=function(){
						if(_xmlhttp.readyState==4){
							if(_xmlhttp.status==200) { 
								//清除定时器
								if(_tm){
									clearTimeout(_tm);
								}

//								var resultStr = decodeURIComponent(_xmlhttp.responseText);
								var resultStr = _xmlhttp.responseText;
								if(null==_success||""==_success||"undefined"==_success||"function"!=typeof(_success)){
//									alert('success为空或不是函数');
									$.getRoot().$.messager.alert('信息提示','success函数为空或不是函数','warning');
								}else{
//									var jobj = $.str2json(resultStr);
//									if("0"==jobj.h_action_code){
//										alert(jobj.h_action_desc);
//									}else{
										_success(resultStr);
//									}
								}
							}
						}
					};
					
					if (_method == "post") {
						_xmlhttp.open (_method,_url,true);
						_xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
						_xmlhttp.setRequestHeader("Content-Length", _param.length);
						_xmlhttp.send(_param);
					}
					else {
						_url += "&"+_param;
						_xmlhttp.open (_method,_url,true);
						_xmlhttp.send(null);
					}
					
					//设置超时定时器
					_tm = setTimeout(
										function(){
											if(null==_ontimeout||""==_ontimeout||"undefined"==_ontimeout||"function"!=typeof(_ontimeout)){
												$.cuajaxTimeout(_xmlhttp);
											}else{
												if (_xmlhttp){
													_xmlhttp.abort();
												}
												_ontimeout();
											}
										}
										,_timeout
									);

			}else{

				if(null==_error||""==_error||"undefined"==_error||"function"!=typeof(_error)){
					//alert("error为空或不是函数");
				}else{
					error("提交的URL不能为空！");
				}
			}	
		}catch(e){
//			alert("ajax提交失败："+e);
			$.getRoot().$.messager.alert('信息提示','ajax提交失败：'+e.message,'error');
		}
	},
	//ajax超时处理		
	cuajaxTimeout:function(xmlhttp){				
		if (xmlhttp){
			xmlhttp.abort();
//			alert('提交请求超时');
			//$.getRoot().$.messager.alert('信息提示','ajax提交请求超时','error');
		}
	},

	//获取当前日期，格式为yyyy-MM-dd
	getDate:function(format){
		if(!format){
			format = "yyyy-MM-dd";
		}
		var date = new Date();
		var y = date.getFullYear();  
		var m = date.getMonth() + 1;  
		var d = date.getDate();  
		var ds = y +  (m < 10 ? '0' + m : m+'') +  (d < 10 ? '0' + d : d+'');
		var datestr = new DateUtil().formateDate(format,ds);
		return datestr;
	},
	//获取当前日期，格式为yyyy-MM-dd HH:mm:ss
	getDateTime:function(format){
		if(!format){
			format = "yyyy-MM-dd HH:mm:ss";
		}
		var date = new Date();
		var y = date.getFullYear();  
		var m = date.getMonth() + 1;  
		var d = date.getDate();  
		
		var h = date.getHours();
		var mm = date.getMinutes();  
		var s = date.getSeconds();
		var ds = y + ( m < 10 ? '0' + m : m+'') +(d < 10 ? '0' + d : d+'')+ (h < 10 ? '0' + h : h+'')+ (mm < 10 ? '0' + mm : mm+'')+ (s < 10 ? '0' + s : s+'');  
		var datestr = new DateUtil().formateDateTime(format,ds);
		return datestr;
	},
	getUUID:function(){
		return $.getID();
	},
	//获取唯一UUID
	getID:function(){
		//
		// Loose interpretation of the specification DCE 1.1: Remote Procedure Call
		// described at http://www.opengroup.org/onlinepubs/009629399/apdxa.htm#tagtcjh_37
		// since JavaScript doesn't allow access to internal systems, the last 48 bits 
		// of the node section is made up using a series of random numbers (6 octets long).
		//  
		var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
		var dc = new Date();
		var t = dc.getTime() - dg.getTime();
		var h = '';
		var tl = UUID.getIntegerBits(t,0,31);
		var tm = UUID.getIntegerBits(t,32,47);
		var thv = UUID.getIntegerBits(t,48,59) + '1'; // version 1, security version is 2
		var csar = UUID.getIntegerBits(UUID.rand(4095),0,7);
		var csl = UUID.getIntegerBits(UUID.rand(4095),0,7);

		// since detection of anything about the machine/browser is far to buggy, 
		// include some more random numbers here
		// if NIC or an IP can be obtained reliably, that should be put in
		// here instead.
		var n = UUID.getIntegerBits(UUID.rand(8191),0,7) + 
				UUID.getIntegerBits(UUID.rand(8191),8,15) + 
				UUID.getIntegerBits(UUID.rand(8191),0,7) + 
				UUID.getIntegerBits(UUID.rand(8191),8,15) + 
				UUID.getIntegerBits(UUID.rand(8191),0,15); // this last number is two octets long
		return tl + h + tm + h + thv + h + csar + csl + h + n; 
	},
	//对象属性复制
	propextend:function(target, source) {
		for (var property in source) {
			target[property] = source[property];
		}
		return target;
	},
	//判断是否为小数
	isNumber:function(numStr){
		var reg = /^[1-9]\d*\.?\d*$/ig;
		return reg.test(numStr);
	},
	/**
	 * 格式化数字显示方式 
	 * 用法
	 * formatNumber(12345.999,'#,##0.00');
	 * formatNumber(12345.999,'#,##0.##');
	 * formatNumber(123,'000000');
	 * @param num
	 * @param pattern
	 */
	number2en:function(num,pattern){
		if(!pattern){
			pattern = '#,##0.0000';
		}
		var strarr = num?num.toString().split('.'):['0'];
		var fmtarr = pattern?pattern.split('.'):[''];
		var retstr='';

		// 整数部分
		var str = strarr[0];
		var fmt = fmtarr[0];
		var i = str.length-1;  
		var comma = false;
		for(var f=fmt.length-1;f>=0;f--){
			switch(fmt.substr(f,1)){
		   		case '#':
		   			if(i>=0 ){
		   				retstr = str.substr(i--,1) + retstr;
		   			}
		   			break;
		   		case '0':
		   			if(i>=0){
		   				retstr = str.substr(i--,1) + retstr;
		   			}else{
		   				retstr = '0' + retstr;
		   			}
		   			break;
		   		case ',':
		   			comma = true;
		   			retstr=','+retstr;
		   			break;
		   		default:
		   			break;
		   	}
		}
		if(i>=0){
			if(comma){
				var l = str.length;
				for(;i>=0;i--){
					retstr = str.substr(i,1) + retstr;
					if(i>0 && ((l-i)%3)==0){
						retstr = ',' + retstr; 
					}
				}
			}else{
				retstr = str.substr(0,i+1) + retstr;
			}
		}

		retstr = retstr+'.';
		// 处理小数部分
		str=strarr.length>1?strarr[1]:'';
		fmt=fmtarr.length>1?fmtarr[1]:'';
		i=0;
		for(var f=0;f<fmt.length;f++){
			switch(fmt.substr(f,1)){
		   		case '#':
		   			if(i<str.length){
		   				retstr+=str.substr(i++,1);
		   			}
		   			break;
		    	case '0':
		    		if(i<str.length){
		    			retstr+= str.substr(i++,1);
		    		}else{
		    			retstr+='0';
		    		}
		    		break;
		    	default:
		    		break;
		    }
		}
		return retstr.replace(/^,+/,'').replace(/\.$/,'');
	},
	number2cn:function(Num){
		Num = Num+'';
		for(i=Num.length-1;i>=0;i--){
			Num = Num.replace(",","");	//替换tomoney()中的“,”
			Num = Num.replace(" ","");	//替换tomoney()中的空格
		}
		Num = Num.replace("￥","");	//替换掉可能出现的￥字符
		if(isNaN(Num)){ //验证输入的字符是否为数字
//			alert("请检查小写金额是否正确");
			$.getRoot().$.messager.alert('信息提示','请检查小写金额是否正确','warning');
			return;
		}
		//字符处理完毕后开始转换，采用前后两部分分别转换
		part = String(Num).split(".");
		newchar = "";
		//小数点前进行转化
		for(i=part[0].length-1;i>=0;i--){
			if(part[0].length > 10){
//				alert("位数过大，无法计算");
				$.getRoot().$.messager.alert('信息提示','位数过大，无法计算','warning');
				return "";
			}//若数量超过拾亿单位，提示
			tmpnewchar = "";
			perchar = part[0].charAt(i);
			switch(perchar){
			   	case "0": tmpnewchar="零" + tmpnewchar ;break;
			   	case "1": tmpnewchar="壹" + tmpnewchar ;break;
			   	case "2": tmpnewchar="贰" + tmpnewchar ;break;
			   	case "3": tmpnewchar="叁" + tmpnewchar ;break;
			   	case "4": tmpnewchar="肆" + tmpnewchar ;break;
			   	case "5": tmpnewchar="伍" + tmpnewchar ;break;
			   	case "6": tmpnewchar="陆" + tmpnewchar ;break;
			   	case "7": tmpnewchar="柒" + tmpnewchar ;break;
			   	case "8": tmpnewchar="捌" + tmpnewchar ;break;
			   	case "9": tmpnewchar="玖" + tmpnewchar ;break;
			}
			switch(part[0].length-i-1){
			   	case 0: tmpnewchar = tmpnewchar +"元" ;break;
			   	case 1: if(perchar!=0)tmpnewchar= tmpnewchar +"拾" ;break;
			   	case 2: if(perchar!=0)tmpnewchar= tmpnewchar +"佰" ;break;
			   	case 3: if(perchar!=0)tmpnewchar= tmpnewchar +"仟" ;break;
			   	case 4: tmpnewchar= tmpnewchar +"万" ;break;
			   	case 5: if(perchar!=0)tmpnewchar= tmpnewchar +"拾" ;break;
			   	case 6: if(perchar!=0)tmpnewchar= tmpnewchar +"佰" ;break;
			   	case 7: if(perchar!=0)tmpnewchar= tmpnewchar +"仟" ;break;
			   	case 8: tmpnewchar= tmpnewchar +"亿" ;break;
			   	case 9: tmpnewchar= tmpnewchar +"拾" ;break;
			}
			newchar = tmpnewchar + newchar;
		}
		//小数点之后进行转化
		if(Num.indexOf(".")!=-1){
			if(part[1].length > 2){
		//		alert("小数点之后只能保留两位,系统将自动截断");
				part[1] = part[1].substr(0,2);
			}
			for(i=0;i<part[1].length;i++){
				tmpnewchar = "";
					perchar = part[1].charAt(i);
					switch(perchar){
					    case "0": tmpnewchar="零" + tmpnewchar ;break;
					    case "1": tmpnewchar="壹" + tmpnewchar ;break;
					    case "2": tmpnewchar="贰" + tmpnewchar ;break;
					    case "3": tmpnewchar="叁" + tmpnewchar ;break;
					    case "4": tmpnewchar="肆" + tmpnewchar ;break;
					    case "5": tmpnewchar="伍" + tmpnewchar ;break;
					    case "6": tmpnewchar="陆" + tmpnewchar ;break;
					    case "7": tmpnewchar="柒" + tmpnewchar ;break;
					    case "8": tmpnewchar="捌" + tmpnewchar ;break;
					    case "9": tmpnewchar="玖" + tmpnewchar ;break;
					}
				if(i==0){
					tmpnewchar =tmpnewchar + "角";
				}
				if(i==1){
					tmpnewchar = tmpnewchar + "分";
				}
				newchar = newchar + tmpnewchar;
			}
		}
		//替换所有无用汉字
		while(newchar.search("零零") != -1){
			newchar = newchar.replace("零零", "零");
		}
		newchar = newchar.replace("零亿", "亿");
		newchar = newchar.replace("亿万", "亿");
		newchar = newchar.replace("零万", "万");
		newchar = newchar.replace("零元", "元");
		newchar = newchar.replace("零角", "");
		newchar = newchar.replace("零分", "");
		if(newchar.charAt(newchar.length-1) == "元" || newchar.charAt(newchar.length-1) == "角"){
			newchar = newchar+"整";
		}
		return newchar;
	},
	
	//获取绝对位置
	getAbsolutePos:function(obj){   
		var pos = {left:obj.offsetLeft,top:obj.offsetTop};   
		if(obj.offsetParent){   
			var tmp = $.getAbsolutePos(obj.offsetParent);   
			pos.left += tmp.left;   
			pos.top += tmp.top;   
		}
		return pos;
	},
	//json转字符串
	json2str:function(o){
		var r = [];
		   if(typeof o == "string" || o == null) {
		     return o;
		   }
		   if(typeof o == "object"){
		     if(!o.sort){
		       r[0]="{";
		       for(var i in o){
		         r[r.length]=i;
		         if(typeof o[i] == "object"){
		        	 r[r.length]=":";
			         r[r.length]=$.json2str(o[i]);
			         r[r.length]=",";
		         }else{
			         r[r.length]=":";
			         r[r.length]="\"";
			         r[r.length]=$.json2str(o[i]);
			         r[r.length]="\"";
			         r[r.length]=",";
		         }
		       }
		       if(r.length>1){
		    	   r[r.length-1]="}";
		       }else{
		    	   r[r.length]="}";
		       }
		     }else{
		       r[0]="[";
		       for(var i =0;i<o.length;i++){
		         r[r.length]=$.json2str(o[i]);
		         r[r.length]=",";
		       }
		       if(r.length>1){
		    	   r[r.length-1]="]";
		       }else{
		    	   r[r.length]="]";
		       }
		     }
		     return r.join("");
		   }
		   return o.toString();
	},
	//字符串转json
	str2json:function(str){
		var eob = null;
		try{
			eob = eval("("+str+")");
		}catch(e){
//			alert('err:'+str);
			if(null!=str&&''!=str){
				$.getRoot().$.messager.alert('信息提示','字符转换错误：'+e.message+'\nstr='+str,'error');
			}
		}
		return eob;
	},
	//改变页脚的左边提示内容
	footerinfo:function(html){
	//	alert($.getRoot().document.getElementById('ifr_footer').contentWindow.document.getElementById('footerinfo'))
		var div = $.getRoot().document.getElementById('ifr_footer').contentWindow.document.getElementById('footerinfo');
		div.innerHTML = html;
	},
	getPagename:function(win){
		if(!win){
			win = window;
		}
		var pagename = win.location.pathname.replace(/(.+)[\/]/,"");
		return pagename;
	},
	timeout:function(){
		alert("登录超时，请重新登录!");
		$.getRoot().document.location.href = $.base()+"/wdk";
	},
	
	/***************************************************
	 * 				查询方案相关方法
	 * @param jparam
	 * @return
	 **************************************************/

	//显示查询界面
	scheme_open:function(jparam){
		try{
			var _url = WDK_ROOT+"/module/frame/public/query_scheme.jsp";
			var _pageurl = jparam.pageurl?jparam.pageurl:'';					//页面ID
			var _pageurlparam = _pageurl;
			var _queryParams = jparam.queryParams?jparam.queryParams:{};		//url请求参数
			var _title = jparam.title?jparam.title:'';							//标题
			var _width = jparam.width?jparam.width:580;							//宽度
			var _height = jparam.height?jparam.height:350;						//高度
			var _modal = jparam.modal?jparam.modal:true;						//是否模态窗口
//			var _callback = jparam.callback?jparam.callback:null;				//回调
			
//			var _callbackStr = "";
//			if(_callback){
//				_callbackStr = $.getFuncName(_callback);
//			}
			
			var _callback = jparam.callback?$.event_getHandler(jparam.callback):function(){};
			var _mid = $.method_reg(window,_callback,jparam);
			var _wid = $.getID();
			var _arr = [];
			for(var att in _queryParams){
				_arr.push(att+'='+_queryParams[att]);
			}
			if(_pageurlparam){
				if(-1==_pageurlparam.indexOf('?')){
					_pageurlparam += '?'+_arr.join('&');
				}else{
					_pageurlparam += '&'+_arr.join('&');
				}
			}
			_url = _url.match(/\?/) ?_url+"&mid="+_mid:_url+"?mid="+_mid;
			_url += '&pageurl='+_pageurl+'&pageurlparam='+$.encode(_pageurlparam);
			$.openWin({
				id:_wid,
				title:_title,
				height:_height,
				width:_width,
				modal:_modal,
				type:'url',
				url:_url,
				modal:true
			});
			
		}catch(e){
			alert(e.message);
		}
	},
	
	//获取字符串的实际像素宽度和高度
	getTextSize:function(text) {
	    var span = document.createElement("span");
	    var result = {};
	    result.width = span.offsetWidth;
	    result.height = span.offsetWidth; 
	    span.style.visibility = "hidden";
	    document.body.appendChild(span);
	    if (typeof span.textContent != "undefined")
	        span.textContent = text;
	    else span.innerText = text;
	    result.width = span.offsetWidth - result.width;
	    result.height = span.offsetHeight - result.height;
	    span.parentNode.removeChild(span);
	    return result;
	},
	//获取页面滚动信息
	getScroll:function(){ 
		var top, left, width, height; 
		if (document.documentElement ) { 
			top = document.documentElement.scrollTop; 
			left = document.documentElement.scrollLeft; 
			width = document.documentElement.scrollWidth; 
			height = document.documentElement.scrollHeight; 
		} else if (document.body) { 
			top = document.body.scrollTop; 
			left = document.body.scrollLeft; 
			width = document.body.scrollWidth; 
			height = document.body.scrollHeight; 
		} 
		return { top: top, left: left, width: width, height: height }; 
	},
	//获取最顶层对象
	getRoot:function(){
		var _top = window.parent;
		while(_top!=_top.parent){
			_top = _top.parent;
		}
		return _top;
	},
	//打开dialog对话框
	showDialog:function(jparam){
		//方法定义在主题最顶层页面中
		 var _top = $.getRoot();
		 _top.showDialog(jparam);
	},
	//dialog自带按钮
	openDialog:function(jparam){
		//方法定义在主题最顶层页面中
		 var _top = $.getRoot();
		 _top.openDialog(jparam);
	},
	dialog_submit:function(wid,jres){
		//方法定义在主题最顶层页面中
		 var _top = $.getRoot();
		 _top.dialog_submit(wid,jres);
	},
	dialog_cancel:function(wid){
		//方法定义在主题最顶层页面中
		 var _top = $.getRoot();
		 _top.dialog_cancel(wid);
	},
	//打开弹出页面
	openWin:function(jparam){
		//方法定义在主题最顶层页面中
		 var _top = $.getRoot();
		 _top.openWin(jparam);
	},
	//关闭弹出页面
	closeWin:function(wid){
		//方法定义在主题最顶层页面中
		var _top = $.getRoot();
		if(!wid){
			wid = $.getURLParam('wid');
		}
		_top.closeWin(wid);
	},
	//注册方法
	//	win:注册页面的window对象
	//	funname:方法函数名,也可以是函数句柄
	//	jparam:附加传递参数
	method_reg:function(win,funname,jparam){
		var _top = $.getRoot();
		var _method = _top._METHOD;
		var _id = $.getID();
		_method[_id]={
				win:win,
				method:funname,
				jparam:jparam
		};
		return _id;
	},
	//执行事件
	//	id:注册方法返回的ID
	//	jparam:调用时传递的参数，json格式
	method_call:function(id,jparam){
		var _top = $.getRoot();
		var _method = _top._METHOD;
		if(_method[id]){
			var _fun = _method[id].method;
			if('string'==typeof(_fun)){
				_fun = _method[id].win[_method[id].method];
			}
			var _v = null;
			try{
				_v = _fun(jparam,_method[id].jparam);
			}catch(e){}
			return _v;
		}else{
		//	alert('id='+id+'   method[id]='+_method[id])
			return null;
		}
	},
	//删除事件
	method_remove:function(jparam){
		
	},
	//注册键盘事件
	keypress_reg:function(keycode,win,funname,jparam){
		var pagename = $.getPagename(win);
		var _keypress = $.getRoot()._KEYPRESS;
		if(!_keypress[pagename]){
			_keypress[pagename] = new Object();
		}
		keycode = keycode.toUpperCase();
		_keypress[pagename][keycode]={
				win:win,
				fun:funname,
				jparam:jparam
		};
		return keycode;
	},
	//调用键盘事件
	keypress_call:function(keycode){
		keycode = keycode.toUpperCase();
		var _keypress = $.getRoot()._KEYPRESS;
		var pagename = $.getPagename(window);
		if(keycode&&_keypress[pagename]&&_keypress[pagename][keycode]){
			var _kp = _keypress[pagename][keycode];
			var _fun = _kp.fun;
			if(_fun){
				if('string'==typeof(_fun)){
					_fun = _kp.win[_fun];
				}
				if(_fun){
					_fun(_kp.jparam);
				}
			}
		}
	},
//	//注册键盘事件
//	keypress_reg:function(keycode,win,funname,jparam){
//		var _top = $.getRoot();
//		var _keypress = _top._KEYPRESS;
//		var _id = keycode.toUpperCase();
//		var _jm = _keypress[_id];
//		if(_jm){
//			return null;
//		}
//		_keypress[_id]={
//				win:win,
//				fun:funname,
//				jparam:jparam
//		};
//		return _id;
//	},
//	//调用键盘事件
//	keypress_call:function(id){
//		id = id.toUpperCase();
//		var _top = $.getRoot();
//		var _keypress = _top._KEYPRESS;
//		if(id&&_keypress[id]){
//			var _fun = _keypress[id].fun;
//			if(_fun){
//				if('string'==typeof(_fun)){
//					_fun = _keypress[id].win[_keypress[id].fun];
//				}
//				if(_fun){
//					_fun(_keypress[id].jparam);
//				}
//			}
//			
//			
////			var _fun = _keypress[id].win[_keypress[id].fun];
////			if(_fun){
////				_fun(_keypress[id].jparam);
////			}
//		}
//	},
	urlparam_encode:function(str){
		if(!str){
			return null;
		}
		str = str.replace(/\'/ig,"\\\'").replace(/\"/ig,"\\\'");
		str = str.replace(/[=]/ig,"###").replace(/[?]/ig,"|||").replace(/[&]/ig,"___");
		var enstr = encodeURI(str);
		return enstr;
	},
	urlparam_decode:function(str){
		if(!str){
			return null;
		}
		var strparam1 = decodeURI(str);
		var strparam2 = strparam1.replace(/\\\'/g,"'");
		strparam2 = strparam2.replace(/###/ig,"=").replace('|||',"?").replace(/___/ig,"&");
		return strparam2;
	},
	json_encode:function(str){
		str = str.replace(/\'/ig,_JSON_ENCODE_SPLIT).replace(/\"/ig,_JSON_ENCODE_SPLIT);
		return;
	},
	json_decode:function(str){
		str = str.replace(/___/ig,'\'');
		return;
	},
	//encode
	encode:function(str){
		var s = encodeURIComponent(str);
		return s;
	},
	//decode
	decode:function(str){
		var s = decodeURIComponent(str);
		return s;
	},
	encodeURI:function(str){
		var s = encodeURI(encodeURI(str));
		return s;
	},
	//required检测
	validate:function(){
		var isok = true;
		$("input").each(function(){
			if('true'==$(this).attr('isrequired')){
				var _class = $(this).attr('class');
				var _value = $(this).val();
				var _id = $(this).attr('id');
				
				if(-1!=_class.indexOf('validatebox')){
					var isvalid = $("#"+_id).validatebox('validate');
					if(isvalid){
						_value = $("#"+_id).val();
					}else{
						_value = null;
					}
				}else if(-1!=_class.indexOf('datebox')){
					_value = $("#"+_id).datebox('getValue');
				}else if(-1!=_class.indexOf('datetimebox')){
					_value = $("#"+_id).datetimebox('getValue');
				}else if(-1!=_class.indexOf('combobox')){
					_value = $("#"+_id).combobox('getValue');
				}else if(-1!=_class.indexOf('inputpop')){
					_value = $("#iph_id_"+_id).val();
				}
				
			//	alert(_value+"    id="+_id+"    "+this.outerHTML);
				if(!_value){
					isok = false;
				}
			}
		});
		return isok;
	},
	//自动读取所有字段的值
	getFieldValue:function(){
		var isok = true;
		var fo = new Object();
		$("input").each(function(){
			var _class = $(this).attr('class');
			var _value = $(this).val();
			var _id = $(this).attr('id');
			if(_class&&_id&&-1==_id.indexOf('iph_')){
				if(-1!=_class.indexOf('validatebox')){
					fo[_id] = $.validatebox_getValue({id:_id});
				}else if(-1!=_class.indexOf('datebox')){
					fo[_id] = $.datebox_getValue({id:_id});
				}else if(-1!=_class.indexOf('datetimebox')){
					fo[_id] = $.datetimebox_getValue({id:_id});
				}else if(-1!=_class.indexOf('combobox')){
					fo[_id] = $.combobox_getValue({id:_id});
				}else if(-1!=_class.indexOf('inputpop')){
					fo[_id] = $("#iph_id_"+_id).val();
				}else if(-1!=_class.indexOf('txt')){
					fo[_id] = $("#"+_id).val();
					//alert('txt.id='+_id);
				}else if(-1!=_class.indexOf('hidden')){
					fo[_id] = $("#"+_id).val();
					//alert('hidden.id='+_id);
				}
			}
		});
		return fo;
	},
	//格式化日期
	//	输入格式：yyyy-MM-dd
	//	输出格式：yyyyMMdd
	formatDate:function(dateStr){
		if(!dateStr){
			return "";
		}
		var a = dateStr.split('-');  
		if(a.length>1){
			dateStr = a[0]+a[1]+a[2];  
		}else{
		}
		return dateStr;
		/*
		var date = new Date(dateStr);
		var y = date.getFullYear();  
		var m = date.getMonth() + 1;  
		var d = date.getDate();  
		return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d);  
		*/
	},
	//格式化日期
	//	输入格式：yyyyMMdd
	//	输出格式：yyyy-MM-dd
	parseDate:function(dateStr){
		var str = s.substring(0,4)+'-'+s.substring(4,6)+'-'+s.substring(6,8);
		return str;
	},
	//格式化日期时间
	//	输入格式：yyyy-MM-dd HH:mm:ss
	//	输出格式：yyyyMMddHHmmss
	formatDateTime:function(dateStr){
		var arr = dateStr.split(' ');  
		if(arr.length>1){
			var a = arr[0].split('-');
			var b = arr[1].split(':');
			dateStr = a[0]+a[1]+a[2]+b[0]+b[1]+b[2];  
		}else{
		}
		return dateStr;  
		/*
		var date = new Date(dateStr);
		var y = date.getFullYear();  
		var m = date.getMonth() + 1;  
		var d = date.getDate();  
		var h = date.getHours();  
		var mm = date.getMinutes();  
		var s = date.getSeconds();  
		return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d)+' '+(h<10?'0'+h:h)+':'+(mm<10?'0'+mm:mm)+':'+(s<10?'0'+s:s);
		*/  
	},
	//格式化日期时间
	//	输入格式：yyyyMMddHHmmss
	//	输出格式：yyyy-MM-dd HH:mm:ss
	parseDateTime:function(dateStr){
		var str = s.substring(0,4)+'-'+s.substring(4,6)+'-'+s.substring(6,8);
		str += ' '+s.substring(8,10)+':'+s.substring(10,12)+':'+s.substring(12,14);
		return str;
	},
	//获取应用部署根路径
	base:function(){
		var urlstr = document.location.href;
		if(urlstr.indexOf("http")!=-1){
			var reg = /http:\/\/[^\/]*/g;
			var httpurl = reg.exec(urlstr)+"";
			var str1 = urlstr.replace(/http:\/\//g,"");
			var reg = /[^\/]*\/[^\/]*/g;
			var str2 = reg.exec(str1)+"";
			var appname = str2.replace(/[^\/]*\//g,"");
			if(urlstr.indexOf(_APPName)!=-1){    
				return httpurl +"/" +appname;
			}else{
				return httpurl;
			}
		}else{
			return "";
		}
	},
	//在当前页面打开等待提示
	wait_open:function(){
		$("#wdk_wait").remove();
		$("#wdk_wait_msg").remove();
		$("<div id=\"wdk_wait\" class=\"datagrid-mask\"></div>").css({display:"block",width:"100%",height:$(window).height()}).appendTo("body"); 
		$("<div id=\"wdk_wait_msg\" class=\"datagrid-mask-msg\"></div>").html("正在处理，请稍候。。。").appendTo("body").css({display:"block",left:($(document.body).outerWidth(true) - 190) / 2,top:($(window).height() - 45) / 2}); 
	},
	//在当前页面关闭等待提示
	wait_close:function(){
		$("#wdk_wait").remove();
		$("#wdk_wait_msg").remove();
	},
	//在顶层框架打开等待提示
	wait_open_top:function(){
		var _top = $.getRoot();
		_top.$("#wdk_wait").remove();
		_top.$("#wdk_wait_msg").remove();
		_top.$("<div id=\"wdk_wait\" class=\"datagrid-mask\"></div>").css({display:"block",width:"100%",height:'100%'}).appendTo("body"); 
		_top.$("<div id=\"wdk_wait_msg\" class=\"datagrid-mask-msg\"></div>").html("正在处理，请稍候。。。").appendTo("body").css({display:"block",left:(document.body.clientWidth) / 2,top:(document.body.clientHieght - 45) / 2}); 
	},
	//在顶层框架关闭等待提示
	wait_close_top:function(){
		var _top = $.getRoot();
		_top.$("#wdk_wait").remove();
		_top.$("#wdk_wait_msg").remove();
	},
	//添加应用日志
	applog:function(jparam){
		var pagename = jparam.pagename;
		if(!pagename){
			pagename = document.title;
			if(!pagename){
				var url = document.location.href;
				pagename=url.substring(url.lastIndexOf("/")+1,url.length);
			}
		}
		//添加日志
		/*var _data = [
		               {name:"pagename",value:pagename},
		               {name:"type",value:jparam.type},
		               {name:"desc",value:jparam.desc}
			     	];
			     	*/
		var _data = {
						pagename:pagename,
						type:jparam.type,
						desc:jparam.desc
					};
		$.cuajax({
		  	url:'wdk?action=wdk.public&method=applog_add&ajaxparam='+new Date().getTime(),
			method:"post", 
			timeout:WDK_Timeout,
			data:_data,   
			success:function(result) {
			},
			error:function(result){
//				alert('网络错误！result='+result);
				$.getRoot().$.messager.alert('信息提示','网络错误：'+result,'error');
			}
		});
	},
	//打开调试debug窗口
	debug:function(jparam){
		var url = $.base()+'/'+WDK_ROOT+'/module/monitor/debug.jsp';
		//window.showModelessDialog(url,null,"dialogWidth=700px;dialogHeight=400px;resizable=1;");
		window.open(url,'控制台调试窗口',"height=400,width=700,left=200,top=200,resizable=yes,scrollings=no,status=no,toolbar=no,menubar=no,location=no");
	},
	//在原来基础上增加，上传维保检测视频
	upload:function(jparam){
		//如果没有指定url则使用系统自带的附件上传功能
		var _catacode = jparam.catacode?jparam.catacode:"";			//没有分类则后台自动指向默认目录
		var _file_types = jparam.file_types?jparam.file_types:'*'; 		//"*.jpg;*.gif;*.png"
		var _callback = jparam.callback?jparam.callback:function(){};
		var _upload_url = jparam.upload_url?jparam.upload_url:'wdk?action=wdk.public&method=attachment_upload&ajaxparam='+new Date().getTime();
		var _personid = jparam.personid?jparam.personid:"";						//上传人员的UUID
		var _frec_uuid = jparam.frec_uuid?jparam.frec_uuid:"";					//检测维保的UUID
		var _fbusiness_type = jparam.fbusiness_type?jparam.fbusiness_type:"";	//检测维保的类型
		var _upload_limit = jparam.upload_limit?jparam.upload_limit:100;		//默认上传文件数量限制
		var _tooss = "1"==jparam.tooss?"1":"0";									//是否上传到oss，0-不上传  1-上传				默认：0
		var _isbackup = "0"==jparam.isbackup?"0":"1";							//是否本地备份，0-不备份，1-本地也备份 		默认：1
		var _ismovie = "1"==jparam.ismovie?"1":"0";								//是否上传视频文件  0-普通文件  1-视频文件		默认：0
		var _file_size_limit = jparam.size_limit?jparam.size_limit:0;		//文件
		_upload_url += '&tooss='+_tooss+'&isbackup='+_isbackup+'&ismovie='+_ismovie;
		//如果上传指定了IP地址，则以指定的IP地址进行上传
		if(-1==_upload_url.indexOf('http')){
			_upload_url = $.base()+'/'+_upload_url;
		}
		_upload_url += "&catacode="+_catacode;
		_upload_url += "&frec_uuid="+_frec_uuid;
		_upload_url += "&fbusiness_type="+_fbusiness_type;
		_upload_url += "&personid="+_personid;
		var settings = {
				flash_url : WDK_ROOT+"/core/js/lib/swfupload/swfupload.swf",
				flash9_url : WDK_ROOT+"/core/js/lib/swfupload/swfupload_fp9.swf",
				upload_url: _upload_url,
				post_params: {"PHPSESSID" : $.getID()},
				file_size_limit :_file_size_limit,
		  		file_types :_file_types ,
				file_types_description : "All Files",
				file_upload_limit : _upload_limit,
				file_queue_limit : 0,
				debug:false,

				// Button settings
				button_image_url: WDK_ROOT+"/core/js/lib/swfupload/XPButtonNoText_61x22.png",
				button_width: "61",
				button_height: "22",
				button_placeholder_id: "spanButtonPlaceHolder",
				button_text: '浏览',
				button_text_left_padding: 15,
				button_text_top_padding: 0,
				
				// The event handler functions are defined in handlers.js
				swfupload_preload_handler : upLoadBox.preLoad,
				swfupload_load_failed_handler : upLoadBox.loadFailed,
				file_queued_handler : upLoadBox.fileQueued,
				file_queue_error_handler : upLoadBox.fileQueueError,
				file_dialog_complete_handler : upLoadBox.fileDialogComplete,
				upload_start_handler : upLoadBox.uploadStart,
				upload_progress_handler : upLoadBox.uploadProgress,
				upload_error_handler : upLoadBox.uploadError,
				upload_success_handler : upLoadBox.uploadSuccess,
				upload_complete_handler : upLoadBox.uploadComplete,
				queue_complete_handler : function(num){
													upLoadBox.colseUploadBox();
													fieldids = upLoadBox.fileids;//.join(',');
													_callback(fieldids);
												}	// Queue plugin event
			};
		upLoadBox.init(settings);
	},
	
	download:function(jparam){
		var _url = jparam.url?jparam.url:'wdk?action=wdk.public&method=attachment_download&ajaxparam='+new Date().getTime();
		var _fileid = jparam.fileid;
		if(-1==_url.indexOf('http')){
			_url = $.base()+"/"+_url;
		}
		_url += "&fileid="+_fileid;
		
		var oDiv = document.getElementById('wdk_download_div');
		if(!oDiv){
			oDiv = document.createElement("DIV");  
			oDiv.id = 'wdk_download_div';
			oDiv.style.visibility = 'visible';  
			oDiv.style.zIndex = -999999;
			oDiv.style.overflow="hidden";
			oDiv.style.width = '0px';
			oDiv.style.height = '0px';
			document.body.appendChild(oDiv); 
		}
		oDiv.innerHTML = '<iframe src="'+_url+'" width="0px" height="0px" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>';
	},
	event_getHandler:function(handler){
		var _handler = handler;
		var _type = typeof(handler);
		if('string'==_type){
			_handler = eval(handler);
		}
		return _handler;
	},
	/*********************************************
	 * 				GRID控件
	 * 	功能说明：
	 * 
	 * 	参数说明：
	 * 
	 *********************************************/
	grid:function(jparam){
		var _id = jparam.id?jparam.id:$.getID();
		var _containerid = jparam.containerid?jparam.containerid:_DEFAULT_containerid;		//容器的ID
		var _gridcode = jparam.gridcode?jparam.gridcode:'';									//grid编码，在数据库中关联表头和格式
		var _title = jparam.title?jparam.title:'';											//标题，可不设置
		var _iconCls = jparam.iconCls?jparam.iconCls:'icon-edit';							//标题前的图标，可不设置
		var _width = jparam.width?jparam.width:'auto';										//宽度
		var _height = jparam.height?jparam.height:'auto';									//高度
		var _nowrap = (false==jparam.nowrap)?jparam.nowrap:true;							//是否不折行
		var _striped = (false==jparam.striped)?jparam.striped:true;							//奇偶行不同颜色
		var _border = (true==jparam.border)?jparam.border:false;							//是否显示边框
		var _collapsible = (true==jparam.collapsible)?jparam.collapsible:false;				//是否可折叠的  
		var _fit = (false==jparam.fit)?jparam.fit:true;										//自动大小
		var _url = jparam.url?jparam.url:'';												//grid数据获取url
		var _initdata = jparam.initdata?jparam.initdata:{};									//新增默认数据
		var _queryParams = jparam.queryParams?jparam.queryParams:{};						//url请求附带参数
		var _toolbar = jparam.toolbar?jparam.toolbar:null;							//关联的工具栏ID
		var _pageSize = jparam.pageSize?jparam.pageSize:10;							//默认每页记录数
		var _pageList = jparam.pageList?jparam.pageList:[10,20,30,40,50];			//每页记录数列表
		var _editortoolbar = jparam.editortoolbar?jparam.editortoolbar:[];					//编辑按钮，包含保存、撤销、删除、新增等操作
		var _editor = jparam.editor?jparam.editor:null;										//编辑列的设置
		var _enableedit = (false==jparam.editor)?jparam.editor:true;						//是否允许开启编辑功能
		
		//如果没有设置editor属性，则当前表格不允许编辑
		if(!_editor){
			_enableedit = false;
		}
		
		var _showEditorStyle = (true==jparam.showEditorStyle)?jparam.showEditorStyle:false;//是否高亮显示可编辑列，默认不高亮列
		
		var _formatter = jparam.formatter?jparam.formatter:{};								//格式化函数
		var _idField = jparam.idField?jparam.idField:'';									//主键字段
		var _sortField = '';//jparam.sortField?jparam.sortField:'';								//可排序字段列表
		if('string'==typeof(_sortField)){
			_sortField = _sortField.split(',');
		}
		var _footer = jparam.footer?jparam.footer:[];										//页脚统计行设置
		
		var _mergeField = '';	//jparam.mergeField?jparam.mergeField:'';					//需合并字段设置，通常用于主表明细表
		var _canMerge = (false==jparam.canMerge)?jparam.canMerge:true;						//是否允许合并
		
		var _singleSelect = (false==jparam.singleSelect)?jparam.singleSelect:true;			//是否单选  
		var _pagination = (true==jparam.pagination)?jparam.pagination:false;				//是否显示分页工具栏 
		var _rownumbers = (false==jparam.rownumbers)?jparam.rownumbers:true;				//是否显示行号
		_rownumbers = true;		//始终为true，有功能需要改功能
		
		var _checkbox = (true==jparam.checkbox)?jparam.checkbox:false;						//是否显示checkbox
		
		var _checkOnSelect = (false==jparam.checkOnSelect)?jparam.checkOnSelect:true;		//选中该行是否联动勾选checkbox
		var _selectOnCheck = (false==jparam.selectOnCheck)?jparam.selectOnCheck:true;		//勾选check是否联动选中改行
		
		var _showContextMenu = (false==jparam.showContextMenu)?jparam.showContextMenu:true;	//是否显示右键菜单
		var _needupanddown = (true==jparam.needupanddown)?jparam.needupanddown:false;		//是否支持上下键盘
		
		var _keyHandler = jparam.keyHandler?jparam.keyHandler:null;							//整个grid的handler
		
		//各类事件
		var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(data){};
		var _onLoadError = jparam.onLoadError?$.event_getHandler(jparam.onLoadError):function(){};
		var _onBeforeLoad = jparam.onBeforeLoad?$.event_getHandler(jparam.onBeforeLoad):function(param){};
		var _onClickRow = jparam.onClickRow?$.event_getHandler(jparam.onClickRow):function(rowIndex, rowData){};
		var _onCheck = jparam.onCheck?$.event_getHandler(jparam.onCheck):function(rowIndex, rowData){};
		var _onUncheck = jparam.onUncheck?$.event_getHandler(jparam.onUncheck):function(rowIndex, rowData){};
		
		var _onDblClickRow = jparam.onDblClickRow?$.event_getHandler(jparam.onDblClickRow):function(rowIndex,rowData){return true;};
		var _onClickCell = jparam.onClickCell?$.event_getHandler(jparam.onClickCell):function(rowIndex, rowData,field,value){};
		var _onDblClickCell = jparam.onDblClickCell?$.event_getHandler(jparam.onDblClickCell):function(rowIndex, rowData,field,value){};
		var _onSortColumn = jparam.onSortColumn?$.event_getHandler(jparam.onSortColumn):function(sort, order){};
		var _onResizeColumn = jparam.onResizeColumn?$.event_getHandler(jparam.onResizeColumn):function(field, width){};
		var _onSelect = jparam.onSelect?$.event_getHandler(jparam.onSelect):function(rowIndex, rowData){};
		var _onUnselect = jparam.onUnselect?$.event_getHandler(jparam.onUnselect):function(rowIndex, rowData){};
		var _onSelectAll = jparam.onSelectAll?$.event_getHandler(jparam.onSelectAll):function(rows){};
		var _onUnselectAll = jparam.onUnselectAll?$.event_getHandler(jparam.onUnselectAll):function(rows){};
		var _onBeforeEdit = jparam.onBeforeEdit?$.event_getHandler(jparam.onBeforeEdit):function(rowIndex, rowData){};
		var _onAfterEdit = jparam.onAfterEdit?$.event_getHandler(jparam.onAfterEdit):function(rowIndex, rowData, changes){};
		var _onCancelEdit = jparam.onCancelEdit?$.event_getHandler(jparam.onCancelEdit):function(rowIndex, rowData){};
		var _onHeaderContextMenu = jparam.onHeaderContextMenu?$.event_getHandler(jparam.onHeaderContextMenu):function(){};
		var _onRowContextMenu = jparam.onRowContextMenu?$.event_getHandler(jparam.onRowContextMenu):function(){};
		
		if(null==_gridcode||""==_gridcode){
			$.getRoot().$.messager.alert('信息提示','gridcode不能为空','error');
			return false;
		}
		
		//1、从后台读取grid配置以及个人默认样式，然后附加datagrid属性
		//var _data = [{name:"gridcode",value:_gridcode}];
		var _data = {gridcode:_gridcode};
		$.cuajax({
		  	url:'wdk?action=wdk.public&method=grid_init&ajaxparam='+new Date().getTime(),
			method:"post", 
			timeout:WDK_Timeout,
			data:_data,   
			success:function(result) {
				var jparam = eval('('+result+')');
				if('-1'==jparam.code){
				}else if('0'==jparam.code){
					$.getRoot().$.messager.alert('信息提示',jparam.desc,'warning');
				}else{
					try{
						_initGrid(jparam);
					}catch(e){
//							alert('报表定义加载错误：'+e.message);
						$.getRoot().$.messager.alert('信息提示','报表定义加载错误：'+e.message,'error');
					}
				}
			},
			error:function(result){
//					alert('网络错误！result='+result);
				$.getRoot().$.messager.alert('信息提示','网络错误：'+result,'error');
			}
		});
		
		var _caption_multystartcol = 0;				//复合表头起始列
		var _caption_level = 0;						//复核表头层级
		
		function _initGridHead(fields){
			//计算总层高
			
			//计算合并行的属性
			var isok = false;
			for(var i=0;i<fields.length;i++){
				var field = fields[i];
				/**
				 * 此段开启将是否高亮可编辑列
				 */
				if(null!=_editor&&true==_showEditorStyle){
					for(var j=0;j<_editor.length;j++){
						var _ed = _editor[j];
						if(field.fieldcode==_ed.field){
							field.iseditor = true;
							break;
						}
					}
				}
				if('1'==field.ismerge){
					_mergeField += field.fieldcode+',';
				}
				if(!field.parentid||""==field.parentid||"0"==field.parentid){
					
				}else{
					if(0==_caption_multystartcol){
						_caption_multystartcol = i;
					}
				}
				captionGetLevel(fields,field,1);
			}
			if(''!=_mergeField){
				_mergeField = _mergeField.substring(0,_mergeField.length-1);
			}
		//	alert("总层高==="+_caption_level+"   _caption_multystartcol="+_caption_multystartcol);

			//计算每个表头的colspan和rowspan以构建多级表头
			for(var i=0;i<fields.length;i++){
				var field = fields[i];
				if(!field.parentid||""==field.parentid||""==field.parentid.trim()||"0"==field.parentid){
					captionIterator(fields,field,0);
				}
			}
			/**/
		}
		//获取caption表头总层高
		function captionGetLevel(fields,pfield,level){
			if(_caption_level < level){
				_caption_level = level;
			}
			for(var i=0;i<fields.length;i++){
				var _field = fields[i];
				if(_field.parentid&&(_field.parentid == pfield.fieldcode)){
					captionGetLevel(fields,_field,level+1);
				}
			}
		};

		//对表头内容进行循环，计算rowspan和colspan
		function captionIterator(fields,pfield,level){
			var childs = [];
			for(var i=0;i<fields.length;i++){
				var cp = fields[i];
				if(cp.parentid == pfield.fieldcode){
					childs.push(cp);
				}
			}
			for(var i=0;i<childs.length;i++){
				var cp = childs[i];
				captionIterator(fields,cp,level+1);
			}
			
			var colspan = 0;
			for(var i=0;i<childs.length;i++){
				var cp = childs[i];
				colspan += cp.colspan;
			}

			pfield.level = level;
			pfield.childlength = childs.length;
			if(childs.length>0){
				pfield.rowspan = 1;
				pfield.colspan = colspan;
			}else{
		//		alert(pfield.fieldname+"=   _caption_level="+_caption_level+"   level="+level);
				pfield.rowspan = _caption_level-level;
				pfield.colspan = 1;
			}
		};
			
		/**
		 * 生成默认的grid html
		 */
		function _GridHTMLDefault(jparam){
			//1、生成默认html
			var arr = [];
			_initGridHead(jparam.fields);
			var frozenCol = 0;			//需要冻结的列数
			if(jparam.fields){
				for(var i=0;i<jparam.fields.length;i++){
					var jfield = jparam.fields[i];
					if(("1"==jfield.isfrozen||"是"==jfield.isfrozen)&&!jfield.parentid){
						frozenCol = i;
					}
				}
			}
			
			//冻结列最大不能超过多级表头起始列
			if(_caption_level>1&&frozenCol>_caption_multystartcol-1){
				frozenCol = _caption_multystartcol-1;
			}
			
			//生成带colspan和rowspan的html
			arr.push('<table id="'+_id+'"  cellspacing="0" cellpadding="0">');
			arr.push('  <thead data-options="frozen:true">');
			for(var i=0;i<_caption_level;i++){
				arr.push('      <tr>');
				if(_checkbox&&0==i){
					arr.push('      	<th rowspan="'+_caption_level+'" colspan="1" data-options="field:\'ck\',checkbox:true"></th>');
				}
				for(var j=0;j<frozenCol;j++){
					var jfield = jparam.fields[j];
					if(jfield.level == i){
						//arr.push('      	<th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true,":"")+'  '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
						arr.push('      	<th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="'+(true==jfield.iseditor?'styler:grid_colsytle_editor,':'')+' field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":("1"==jfield.issort?",sortable:true":""))+'  '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
					}
				}
			}
			
			arr.push('      </tr>');
			arr.push('  </thead>');
			arr.push('  <thead>');
			for(var i=0;i<_caption_level;i++){
				arr.push('      <tr>');
				for(var j=frozenCol;j<jparam.fields.length;j++){
					var jfield = jparam.fields[j];
				//	alert("j="+j+"  jfield.level="+jfield.level+"   i="+i)
					if(jfield.level == i){
						//arr.push('      	<th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":"")+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
						arr.push('      	<th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="'+(true==jfield.iseditor?'styler:grid_colsytle_editor,':'')+' field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":("1"==jfield.issort?",sortable:true":""))+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
					}
				}
			}
			arr.push('      </tr>');
			arr.push('  </thead>');
			arr.push('</table>');
			return arr.join('');
			
		}
		
		/**
		 * 根据个人设置生成HTML
		 */
		function _GridHTMLFormat(jparam){
			//1、生成默认html
			var arr = [];
			_initGridHead(jparam.format.fieldstyle);
			
			var frozenCol = 0;			//需要冻结的列数
			
			if(jparam.format.fieldstyle){
				for(var i=0;i<jparam.format.fieldstyle.length;i++){
					var jfield = jparam.format.fieldstyle[i];
					if(("1"==jfield.isfrozen||"是"==jfield.isfrozen)&&!jfield.parentid){
						frozenCol = i;
					}
				}
			}

			//冻结列最大不能超过多级表头起始列
			if(_caption_level>1&&frozenCol>_caption_multystartcol-1){
				frozenCol = _caption_multystartcol-1;
			}
			//生成带colspan和rowspan的html
			arr.push('<table id="'+_id+'"  cellspacing="0" cellpadding="0">');
			arr.push('  <thead data-options="frozen:true">');
			for(var i=0;i<_caption_level;i++){
				arr.push('      <tr>');
				if(_checkbox&&0==i){
					arr.push('      	<th rowspan="'+_caption_level+'" colspan="1" data-options="field:\'ck\',checkbox:true"></th>');
				}
				for(var j=0;j<frozenCol;j++){
					var jfield = jparam.format.fieldstyle[j];
					if(jfield.level == i){
						//var formatstr = _getFormat(jfield.dataformat);
						//arr.push('      	<th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":"")+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
						arr.push('      	<th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="'+(true==jfield.iseditor?'styler:grid_colsytle_editor,':'')+' field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":("1"==jfield.issort?",sortable:true":""))+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
					}
				}
			}
			arr.push('      </tr>');
			arr.push('  </thead>');
			arr.push('  <thead>');
			for(var i=0;i<_caption_level;i++){
				arr.push('      <tr>');
				for(var j=frozenCol;j<jparam.format.fieldstyle.length;j++){
					var jfield = jparam.format.fieldstyle[j];
					if(jfield.level == i){
						//arr.push('      	<th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":"")+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
						arr.push('      	<th rowspan="'+jfield.rowspan+'" colspan="'+jfield.colspan+'" '+(jfield.colspan==1?'data-options="'+(true==jfield.iseditor?'styler:grid_colsytle_editor,':'')+' field:\''+jfield.fieldcode+'\',width:'+jfield.width+',align:\''+jfield.align+'\' '+(_formatter[jfield.fieldcode]?',formatter:'+_formatter[jfield.fieldcode]:(jfield.dataformat?',formatter:'+_getFormat(jfield.dataformat):''))+' '+("1"==jfield.datatype?",sorter:_sort_number":"")+' '+(_sortField.contains(jfield.fieldcode)?",sortable:true":("1"==jfield.issort?",sortable:true":""))+' '+(("1"==jfield.ishidden||"是"==jfield.ishidden)?",hidden:true":"")+'"':"")+'>'+jfield.fieldname+'</th>');
					}
				}
			}
			arr.push('      </tr>');
			arr.push('  </thead>');
			arr.push('</table>');

			return arr.join('');
		}
		
		
		
		function _initGrid(jparam){
			var gridHTML = "";
			if(jparam.format&&jparam.format.fieldstyle){
				gridHTML = _GridHTMLFormat(jparam);
			}else{
				gridHTML = _GridHTMLDefault(jparam);
			}
			$("#"+_containerid).html(gridHTML);
			//加载grid数据
			if(_footer.length>0){
				_queryParams.footer = $.json2str(_footer);
			}
			if(!_queryParams.orderbyfield){
				_queryParams.orderbyfield = _idField;
			}
			_queryParams.mergefield = _mergeField;
			
			$('#'+_id).datagrid({  
				gridid:_id,
				containerid:_containerid,
		        title:_title,  
		        iconCls:_iconCls,		//图标  
		        width: _width,  
		        height: _height,  
		        nowrap: _nowrap,  
		        striped:_striped,  
		        border:_border,  
		        checkOnSelect:_checkOnSelect,
		        selectOnCheck:_selectOnCheck,
		        collapsible:_collapsible,		//是否可折叠的  
		        fit:_fit,						//自动大小
		        url:_url,
		        initdata:_initdata,
		        pageSize:_pageSize,				//分页每页记录数
		        pageList:_pageList,
		        toolbar:'#'+_toolbar,
		        queryParams:_queryParams,
		        remoteSort:false,   
		        canMerge:_canMerge,
		        idField:_idField,  
		        editor:_editor,
		        copyrows:[],					//被复制的行
		        enableedit:_enableedit,
		        keyHandler:_keyHandler,
		        footer:_footer,
		        showFooter:_footer.length>0?true:false,
		        singleSelect:false,				//是否单选，始终false，始终可以多选，通过ctrl来控制
		        pagination:_pagination,			//分页控件  
		        rownumbers:_rownumbers,			//行号 
		        editrowindex:-1,				//编辑的行号
		        selectrowindex:-1,				//选中的行号
		        //加载完成后进行合并行操作
		        onLoadSuccess:function(data){
		        	if(_singleSelect){
		    			$('#'+_id).datagrid('clearSelections');  
		    		}
		            if (data.rows.length>0){
		            	//调用mergeCellsByField()合并单元格
		            	if(_canMerge&&_mergeField&&""!=_mergeField){
		            		$.grid_merge(_id,_mergeField);
		            	}
		            }
		            //将所有editor.type=checkbox的field初始化变为复选框
		            if(_editor){
		            	var _chkfields = [];
			            for(var i=0;i<_editor.length;i++){
			            	var _ed = _editor[i];
			            	if('checkbox'==_ed.editor.type){
			            		_chkfields.push(_ed.field);
			            	}
			            }
			            if(_chkfields.length>0){
			            	var _div = $('#'+_id).datagrid('getPanel').find('div.datagrid-body')[1];
		            		for(var i = 0;i<data.rows.length;i++){
		            			var _d = data.rows[i];
		            			for(var j=0;j<_chkfields.length;j++){
				            		var _fid = _chkfields[j];
				            		var htmlstr = '';
				            		if('1'==_d[_fid]){
				            			htmlstr = '<input type="checkbox" checked disabled>';
				            		}else{
				            			htmlstr = '<input type="checkbox" disabled>';
				            		}
				            		
		                    		$('#'+_id).datagrid('getData').rows[i][_fid] = htmlstr;
		                            var _cnt = $(_div).find('table tbody tr:eq('+i+') td[field="'+_fid+'"] div');
		                            $(_cnt).html(htmlstr);
		            			}
		            		}
			            }
		            }
		            _onLoadSuccess(data);
		        },
		        //加载右键菜单
		        onRowContextMenu: function(e, rowIndex, rowData) { //右键时触发事件
		             //三个参数：e里面的内容很多，真心不明白，rowIndex就是当前点击时所在行的索引，rowData当前行的数据
		        	if(!_showContextMenu){
		        		return false; 
		        	}
		        	e.preventDefault(); //阻止浏览器捕获右键事件
//		             $(this).datagrid("clearSelections"); //取消所有选中项
//		             $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
		        	
		        	var _menuid = $.getUUID();
		        	$("body").append('<div id="'+_menuid+'" keepshow="true" class="easyui-menu" style="width:120px;"></div>');
		                      
		             if(!$('#'+_menuid).html()){
		            	//如果右键菜单还没有构建，则实时构建
		            	 var arr = [];
		            	 arr.push('<div id="e_'+_menuid+'">');
		            	 arr.push('	<span>导出</span>');
		            	 arr.push('	<div id="exp_'+_menuid+'">');
			             arr.push('		<div onclick="_handler_grid_export2excel_page(\''+_gridcode+'\',\''+_id+'\',\'0\')">导出本页</div>');
			             arr.push('		<div onclick="_handler_grid_export2excel_total(\''+_gridcode+'\',\''+_id+'\',\'0\')">导出全部</div>');
			             arr.push('		<div onclick="_handler_grid_export2excel_page(\''+_gridcode+'\',\''+_id+'\',\'1\')">导出本页【支持合并】</div>');
			             arr.push('		<div onclick="_handler_grid_export2excel_total(\''+_gridcode+'\',\''+_id+'\',\'1\')">导出全部【支持合并】</div>');
			             arr.push('		<div class="menu-sep"></div>');
			             arr.push('		<div onclick="_handler_grid_export2excel_template(\''+_gridcode+'\',\''+_id+'\')">导出EXCEL模板</div>');
			             arr.push('	</div>');
			             arr.push('</div>');
			             arr.push('<div onclick="_handler_grid_import(\''+_gridcode+'\',\''+_id+'\')">数据导入</div>');
			             arr.push('<div class="menu-sep"></div>');
			             arr.push('<div id="grid_copy_button">复制</div>');
			             arr.push('<div>');
		            	 arr.push('	<span>粘贴</span>');
		            	 arr.push('	<div>');
			             arr.push('		<div onclick="_handler_grid_paste(\''+_gridcode+'\',\''+_id+'\',\''+_idField+'\',\'1\')">粘贴到当前行之上 </div>');
			             arr.push('		<div onclick="_handler_grid_paste(\''+_gridcode+'\',\''+_id+'\',\''+_idField+'\',\'0\')">粘贴到当前行之下 </div>');
			             arr.push('		<div onclick="_handler_grid_paste(\''+_gridcode+'\',\''+_id+'\',\''+_idField+'\',\'2\')">粘贴到第一行 </div>');
			             arr.push('		<div onclick="_handler_grid_paste(\''+_gridcode+'\',\''+_id+'\',\''+_idField+'\',\'3\')">粘贴到最末行 </div>');
			             arr.push('	</div>');
			             arr.push('</div>');
			          	 arr.push('<div class="menu-sep"></div>');
			             arr.push('<div onclick="_handler_grid_formatset(\''+_gridcode+'\',\''+_id+'\',\''+_containerid+'\')">表格设置</div>');   
				         arr.push('<div onclick="_handler_grid_formatload(\''+_gridcode+'\',\''+_id+'\')" iconCls="icon-undo">恢复默认设置</div>');
				         
		            	 $('#'+_menuid).html(arr.join(''));
		            	 $('#'+_menuid).menu();
		             }
		             $('#'+_menuid).menu('show', {		//显示右键菜单
		                 left: e.pageX,//在鼠标点击处显示菜单
		                 top: e.pageY
		             	});
		             
		             //绑定复制功能
		             try{
		            	 //生成复制文本
		            	 $("#grid_copy_button").zclip({
		         			path: WDK_ROOT+'/core/js/lib/zclip/ZeroClipboard.swf',
		         			copy: function(){
			            		 var _copyrows = $.grid_getSelections({
										id:_id
									});
				            	 
				            	 //保留复制的行，以便粘贴用
				            	 $('#'+_id).datagrid('options').copyrows = _copyrows;
				            	 
				            	 var arr = [];
				            	 for(var i=0;i<_copyrows.length;i++){
				            		 var row = _copyrows[i];
				            		 for(var att in row){
				            			arr.push(row[att]+'\t');
				            		 }
				            		 arr.push('\n');
				            	 } 
				            	 return arr.join('');
		            	 	},
		         			afterCopy: function(){
		            		 	//alert('复制成功');
		         			}
		         		});		             
		             }catch(e){
//		            	 alert(e.message);
		            	 $.getRoot().$.messager.alert('信息提示','表格右键功能错误：'+e.message,'error');
		             }
		            
		         },
		         onSortColumn:function(sort,order){  
		        	 $(this).datagrid('options').queryParams.orderbyfield = sort+' '+order;
		        	 $(this).datagrid('reload');  
		        	 //var _queryParams = $(this).datagrid('options').queryParams;
		        	// _queryParams.orderbyfield = sort+' '+order;
		        	// $(this).datagrid({queryParams:_queryParams});
		        	// alert(2222223);
		        	// return false;
//		             $.grid_reload({
//		            	 			id:_id,
//		            	 			queryParams:$(this).datagrid('options').queryParams
//		            	 		});
		         },
		         //注册各类事件
		         onLoadError:function(){
		        	 _onLoadError();
		         },
		         onBeforeLoad:function(param){
		        	 _onBeforeLoad(param); 
		         },
		         onCheck:function(rowIndex, rowData){
		        	_onCheck(rowIndex,rowData);
		         },
		         onUncheck:function(rowIndex, rowData){
		        	_onUncheck(rowIndex,rowData);
		         },
		         onClickRow:function(rowIndex, rowData){
		        	 event_gridid = _id;
		        	 if(_singleSelect&&!event_key_isCTRL){
		        		$('#'+_id).datagrid('unselectAll'); 
		        		$('#'+_id).datagrid('selectRow', rowIndex);
		        	 }
		        	 var isok = $.grid_editor_ending({id:_id});
		        	 if(isok){
			        	 $("#"+_id).datagrid('options').selectrowindex = rowIndex;
			        	 
//			        	 var isSelected = false;
//			        	 var rows = $("#"+_id).datagrid("getSelections");
//			        	 
//			        	 for(var i=0;i<rows.length;i++){
//			        		 var _rowIndex = $("#"+_id).datagrid("getRowIndex", rows[i]);
//			        		 alert('rowIndex='+rowIndex+'  _rowIndex='+_rowIndex);
//			        		 if(_rowIndex==rowIndex){
//			        			 alert('找到了');
//			        			 isSelected = true;
//			        			 break;
//			        		 }
//			        	 }
//			        	 
//			        	 alert('选中的行数：'+rows.length+'   isSelected='+isSelected);
//			        	 
//			        	 if(isSelected){
//			        		 $('#'+_id).datagrid('unselectRow', rowIndex);
//			        	 }else{
//			        		 $('#'+_id).datagrid('selectRow', rowIndex);
//			        	 }
//	//		        	 $.grid_editor_onClick
//	//		     		_handler_grid_toolbar_endEditing(_id);
//	//		     		if(_editor){
//	//		     			_handler_grid_onClickRow(_id,rowIndex);
//	//		     		}
			     		_onClickRow(rowIndex, rowData);
		        	 }
		         },
		         onDblClickRow:function(rowIndex,rowData){
		        	 if($.grid_editor_ending({id:_id})){
			        	 var isok = _onDblClickRow(rowIndex,rowData);
			        	 if(false!=isok){
			        		 $("#"+_id).datagrid('options').editrowindex = rowIndex;
				        	 $("#"+_id).datagrid('options').selectrowindex = rowIndex;
				        	
				        	 $.grid_editor_beginEdit({id:_id,type:'edit',rowIndex:rowIndex});
			        	 }

	//		        	 if(isok&&_editor){
	//		        		 _handler_grid_onDblClickRow(_id,rowIndex);
	//		     		 }
		        	 }
		         },
		         onClickCell: function (rowIndex, field, value) { 
		        	 if($.grid_editor_ending({id:_id})){
			        	 $("#"+_id).datagrid('options').selectrowindex = rowIndex;
//			        	 $('#'+_id).datagrid('selectRow', rowIndex);
		        	 
	//		        	 _handler_grid_toolbar_endEditing(_id);
	//			     	 if(_editor){
	//			     		_handler_grid_onClickRow(_id,rowIndex);
	//			     	 }
				     	 var rows = $('#'+_id).datagrid('getRows');
			        	 _onClickCell(rowIndex,rows[rowIndex],field,value);
		        	 }
		         },
		         onDblClickCell: function (rowIndex, field, value) {
		        	 if($.grid_editor_ending({id:_id})){
		        		 $("#"+_id).datagrid('options').editrowindex = rowIndex;
			        	 $("#"+_id).datagrid('options').selectrowindex = rowIndex;
			        	 
	//		        	 _handler_grid_toolbar_endEditing(_id);
	//			     	 if(_editor){
	//			     		_handler_grid_onClickRow(_id,rowIndex);
	//			     	 }
				     	 var rows = $('#'+_id).datagrid('getRows');
				     	_onDblClickCell(rowIndex,rows[rowIndex],field,value);
		        	 }
		         },
		         onResizeColumn:function(field,width){
		        	 _onResizeColumn(field,width);
		         },
		         onSelect:function(rowIndex, rowData){
		        	 _onSelect(rowIndex, rowData);
		         },
		         onUnselect:function(rowIndex, rowData){
		        	 _onUnselect(rowIndex, rowData);
		         },
		         onSelectAll:function(rows){
		        	 _onSelectAll(rows);
		         },
		         onUnselectAll:function(rows){
		        	 _onUnselectAll(rows);
		         },
		         onBeforeEdit:function(rowIndex, rowData){
			    	_onBeforeEdit(rowIndex,rowData);
			     },
		         onAfterEdit:function(rowIndex,rowData,changes){
			    	 _onAfterEdit(rowIndex,rowData,changes);
			     },
		         onCancelEdit:function(rowIndex, rowData){
			    	 _onCancelEdit(rowIndex,rowData);
			     },
		         onHeaderContextMenu:_onHeaderContextMenu
		    }); 
			
			//开通上下键盘移动
			if(_needupanddown){
				$('#'+_id).datagrid({}).datagrid("keyCtr");
			}
			if(_keyHandler){
				$('#'+_id).datagrid("keyHandler");
			}
			
			//设置分页控件  
			if(_pagination){
			    var p = $('#'+_id).datagrid('getPager');  
			    $(p).pagination({  
			        pageSize: _pageSize,//每页显示的记录条数，默认为10  
			        pageList: _pageList,//可以设置每页记录条数的列表  
			        beforePageText: '第',//页数文本框前显示的汉字  
			        afterPageText: '页    共 {pages} 页',  
			        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'  
//			       ,onBeforeRefresh:function(){    
//			           alert('before refresh');
//			           $(this).pagination('loading');
//				       alert('pageNumber:'+pageNumber+',pageSize:'+pageSize);
//				       $(this).pagination('loaded');
//			    	},
//			    	onRefresh:function(pageNumber,pageSize){    
//			           alert(pageNumber);    
//			           alert(pageSize);    
//			        },    
//			       ,onChangePageSize:function(){    
//			           alert('pagesize changed'); 
//			        }    
//			        ,onSelectPage:function(pageNumber,pageSize){
//				    	alert('onSelectPage  _singleSelect='+_singleSelect);
//			    		if(_singleSelect){
//			    			$('#'+_id).datagrid('unselectAll');  
//			    		}
//			    		this.onSelectPage(pageNumber, pageSize);
//			           alert(pageNumber);    
//			           alert(pageSize);    
//			        }    
			    });  
			}
			//设置可编辑
			if(_editor){
			//	$("#grid_toolbar").css("display","block");
//				$('#grid_toolbar_append').linkbutton({ plain:true,iconCls:'icon-add'}); 
//				$('#grid_toolbar_remove').linkbutton({ plain:true,iconCls:'icon-remove'}); 
//				$('#grid_toolbar_ending').linkbutton({ plain:true,iconCls:'icon-save'}); 
//				$('#grid_toolbar_reject').linkbutton({ plain:true,iconCls:'icon-undo'}); 
//				$('#grid_toolbar_getchanges').linkbutton({ plain:true,iconCls:'icon-search'}); 
				
		/*		$("#"+_id).datagrid({
					onClickRow:function(index){_handler_grid_onClickRow(_id,index);},
					onDblClickRow: function(index){_handler_grid_onDblClickRow(_id,index);}
//					,toolbar:'#grid_toolbar'
				});
				*/
				$("#"+_id).datagrid('addEditor', _editor);
			}
//			if(_toolbar){
//				$("#"+_id).datagrid({toolbar:'#'+_toolbar});
//			}
//			if(_toolbar&&_editortoolbar.length==0){
//				$("#"+_id).datagrid({toolbar:'#'+_toolbar});
//			}
		}
		return _id;
	},
	//grid的重新加载，用于条件查询等
	grid_reload:function(jparam){
		var _id = jparam.id;
		var _opts = $('#'+_id).datagrid('options');
		var _newQueryParams = jparam.queryParams?jparam.queryParams:{};
		var _oldQueryParams = _opts.queryParams;
		for(var att in _newQueryParams){
			_oldQueryParams[att] = _newQueryParams[att];
		}
	//	$('#'+_id).datagrid({queryParams:_oldQueryParams});
		$('#'+_id).datagrid('reload',_oldQueryParams);
		/*
		//设置分页控件  
	    var p = $('#'+_id).datagrid('getPager');  
	    $(p).pagination({  
	        pageSize: _opts.pageSize,//每页显示的记录条数，默认为10  
	        pageList: _opts.pageList,//可以设置每页记录条数的列表  
	        beforePageText: '第',//页数文本框前显示的汉字  
	        afterPageText: '页    共 {pages} 页',  
	        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'  
	    });  
	    */
	    //取消所有选中的行
//	    $('#'+_id).datagrid('unselectAll');
	    $('#'+_id).datagrid('clearSelections');

	},
	//读取所有列的实际列宽
	//返回，包含字段和字段实际宽度
	grid_getColWidth:function(jparam){
		var obj = new Object();
		var _id = jparam.id;
		var _tbody1 = $('#'+_id).find('div[class][class="panel datagrid"] div.datagrid-view1 div.datagrid-header div.datagrid-header-inner table.datagrid-htable  tbody');
		$(_tbody1).find("tr").each(function(){
			var tr = $(this);
			tr.find("td").each(function(){
				var td = $(this);
				var _field = td.attr('field');
				if(_field&&'ck'!=_field){
					if('1'==td.attr('colspan')){
						var _divCell = td.find('div.datagrid-cell');
						var _width = $(_divCell).css('width');
						_width = _width.replace('px','');
						_width = parseInt(_width);
						if(0!=_width){
							_width += 8;		//增加
						}
						obj[_field] = _width;
					}
				}
			});
		});
		var _tbody2 = $('#'+_id).find('div[class][class="panel datagrid"] div.datagrid-view2 div.datagrid-header div.datagrid-header-inner table.datagrid-htable  tbody');
		$(_tbody2).find("tr").each(function(){
			var tr = $(this);
			tr.find("td").each(function(){
				var td = $(this);
				var _field = td.attr('field');
				if(_field&&'ck'!=_field){
					if('1'==td.attr('colspan')){
						var _divCell = td.find('div.datagrid-cell');
						var _width = $(_divCell).css('width');
						_width = _width.replace('px','');
						_width = parseInt(_width);
						if(0!=_width){
							_width += 8;
						}
						obj[_field] = _width;
					}
				}
			});
		});
		return obj;
	},
	
	//绑定grid的editor的点击事件
	//该事件绑定在开始编辑之后
	grid_editor_bindClick:function(jparam){
		var _id = jparam.id;
		var _rowIndex = jparam.rowIndex;
		var _row = $.grid_getRow({
			id:_id
			,rowIndex:_rowIndex
		}); 
		var _type = jparam.type;
		var eds = $('#'+_id).datagrid('getEditors', _rowIndex);
        for (var i = 0; i < eds.length; i++){
        	var ed = eds[i];
        	var _value = '';
        	if("inputpop"==ed.type){
        		_value = $(ed.target).parent().find('input.inputpop_input').val();
        	}else{
        		_value = $(ed.target).val();
        	}
            
            var _keyUp_mid = '';
            //查看是否有其他的事件需要关联
            var co = $('#'+_id).datagrid('getColumnOption',ed.field);
            if(co.editor.options){
	            if(co.editor.options.onClick){
	            	$(ed.target).bind('click',{id:_id,ed:ed,value:_value,row:_row,rowIndex:_rowIndex},$.event_getHandler(co.editor.options.onClick));
	            }
	            if(co.editor.options.onChange){
	            	$(ed.target).bind('change',{id:_id,ed:ed,value:_value,row:_row,rowIndex:_rowIndex},$.event_getHandler(co.editor.options.onChange));
	            }
	            if(co.editor.options.onKeyPress){
	            	$(ed.target).bind('keypress',{id:_id,ed:ed,value:_value,row:_row,rowIndex:_rowIndex},$.event_getHandler(co.editor.options.onKeyPress));
	            }
	            if(co.editor.options.onKeyUp){
	            	_keyUp_mid = $.method_reg(window,$.event_getHandler(co.editor.options.onKeyUp));
	            }
	            if(co.editor.options.onKeyDown){
	            	$(ed.target).bind('keydown',{id:_id,ed:ed,value:_value,row:_row,rowIndex:_rowIndex},$.event_getHandler(co.editor.options.onKeyDown));
	            }
	            
//	            $(ed.target).bind('keyup',{id:_id,ed:ed,value:_value,row:_row,rowIndex:_rowIndex},$.event_getHandler(co.editor.options.onKeyUp));
            }
            $(ed.target).bind('keyup',{id:_id,ed:ed,rowIndex:_rowIndex,keyUp_mid:_keyUp_mid},grid_editor_onClick);
         }
        //1、首先将光标置于第一个editor上
        
        //如果是inputpop，则弹出
//       if('append'==_type&&$(eds[0].target).find('input.inputpop_input').length>0){
//        	//$(eds[0].target).find('#inputpop_arrow_click').trigger("click");
//    	   $(eds[0].target).find('.inputpop_input').focus();
//    	   $(eds[0].target).find('.inputpop_input').select();
//        }else{
//        	//否则，聚焦
//        	if(eds[0]&&$(eds[0].target)){
//	        	$(eds[0].target).focus();
//	        	$(eds[0].target).select();
//        	}
//        }
	},
	grid_getEditorValue:function(_ed){
		var _value = '';
    	if("inputpop"==_ed.type){
    		_value = $(_ed.target).parent().find('input.inputpop_input').val();
    	}else{
    		_value = $(_ed.target).val();
    	}
    	return _value;
	},
	//光标聚焦到下一个
	grid_editor_next:function(jparam){
		var _id = jparam.id;
		var _edpos = jparam.edpos;
		var _rowIndex = jparam.rowIndex;
		var eds = $('#'+_id).datagrid('getEditors', _rowIndex);
		var rows = $('#'+_id).datagrid('getRows');
		if(-1==_edpos){
			return false;
		}
		var nextpos = _edpos+1;
	//	alert('newpos='+newpos);
		//如果超出了，则新增一行
		if(nextpos>=eds.length){
//			//如果当前行不在最后一行，则移动到下一行,否则开启新的一行
//		//	alert('_rowIndex='+_rowIndex+'   rows.length='+rows.length)
//			if(_rowIndex+1>=rows.length){
//				$('#'+_id).datagrid('endEdit', _rowIndex);
//			
//				//	$.grid_editor_append({id:_id});
//			}else{
//				//_handler_grid_toolbar_endEditing(_id);
//				$('#'+_id).datagrid('endEdit', _rowIndex);
//				$.grid_editor_beginEdit({id:_id,type:'edit',rowIndex:_rowIndex+1});
//			}
//			
		}else{
	        var ed = eds[nextpos];
	        if(ed){
		        if($(ed.target).find('input.inputpop_input').length>0){
		        	//$(ed.target).find('#inputpop_arrow_click').trigger("click");
		        	$(ed.target).find('input.inputpop_input').focus();
		        	$(ed.target).find('input.inputpop_input').select();
		        }else{
		        	$(ed.target).focus();
		        	$(ed.target).select();
		        }
	        }
		}
	},
	//开始编辑
	grid_editor_beginEdit:function(jparam){
		var _id = jparam.id;
		 var editors = $('#'+_id).datagrid('options').editor;
		 if(!editors||0==editors.length){
			 return false;
		 }
		var _enableedit = $('#'+_id).datagrid('options').enableedit;
		if(_enableedit){
			//alert('允许编辑');
		}else{
			//alert('禁止编辑');
			return false;
		}
		var _rowIndex = jparam.rowIndex;
		var _type = jparam.type;		//新增还是修改
		$('#'+_id).datagrid('selectRow', _rowIndex).datagrid('beginEdit', _rowIndex);
		//给grid的editor绑定点击事件
		$.grid_editor_bindClick({id:_id,rowIndex:_rowIndex,type:_type});
		
	},
	//可编辑grid：结束编辑
	grid_editor_ending:function(jparam){
		var _id = jparam.id;
		var _editrowindex = $('#'+_id).datagrid('options').editrowindex;
		if (-1==_editrowindex){return true;}
	    if ($('#'+_id).datagrid('validateRow', _editrowindex)){
	        $('#'+_id).datagrid('endEdit', _editrowindex);
			$('#'+_id).datagrid('options').editrowindex = -1;
	        return true;
	    } else {
	        return false;
	    }
	},//可编辑grid： 退出编辑
	grid_editor_cancel:function(jparam){
		var _id = jparam.id;
//		_handler_grid_toolbar_endEditing(_id);
		
		var _editrowindex = $('#'+_id).datagrid('options').editrowindex;
		if (-1==_editrowindex){return true;}
        $('#'+_id).datagrid('cancelEdit', _editrowindex);
		$('#'+_id).datagrid('options').editrowindex = -1;
        return true;
	},
	//可编辑grid：新增行
	grid_editor_append:function(jparam){
		var _id = jparam.id;
		var _data = jparam.data;
		
		var _beginedit = (true==jparam.beginedit)?jparam.beginedit:false;	//是否直接开启编辑
		if(!jparam.data){
	//		_data = $('#'+_id).datagrid('options').initdata;
		}
		if ($.grid_editor_ending({id:_id})){
			if(!_data){
				_data = {};
			}
			//防止引用

    		$('#'+_id).datagrid('unselectAll'); 
			$('#'+_id).datagrid('appendRow',_data);
			var _index = $('#'+_id).datagrid('getRows').length-1;
			$("#"+_id).datagrid("options").selectrowindex = _index;
			$('#'+_id).datagrid('selectRow', _index);
			if(true==_beginedit){
		       	$("#"+_id).datagrid("options").editrowindex = _index;
		     	$.grid_editor_beginEdit({id:_id,type:'append',rowIndex:_index});
		   	}
		}

		var _editor = $('#'+_id).datagrid('options').editor;
		
		//改变所有editor.type=checkbox的显示内容,只有当不开启编辑状态时才改变checkbox的显示内容
		//因为不开启编辑状态初始化下checkbox不显示任何内容，不直观
		if(_editor&&true!=_beginedit){
        	var _chkfields = [];
            for(var i=0;i<_editor.length;i++){
            	var _ed = _editor[i];
            	if('checkbox'==_ed.editor.type){
            		_chkfields.push(_ed.field);
            	}
            }
            if(_chkfields.length>0){
            	var _div = $('#'+_id).datagrid('getPanel').find('div.datagrid-body')[1];
            	var _selectIndex = $("#"+_id).datagrid("options").selectrowindex;
            	var _data = $.grid_getRows({id:_id});
    			var _d = _data[_selectIndex];
    			
    			for(var j=0;j<_chkfields.length;j++){
            		var _fid = _chkfields[j];
            		var htmlstr = '';
            		if('1'==_d[_fid]){
            			htmlstr = '<input type="checkbox" style="align:center" checked disabled>';
            		}else{
            			htmlstr = '<input type="checkbox" style="align:center" disabled>';
            		}
            		$('#'+_id).datagrid('getData').rows[_selectIndex][_fid] = htmlstr;
                    var _cnt = $(_div).find('table tbody tr:eq('+_selectIndex+') td[field="'+_fid+'"] div');
                    $(_cnt).html(htmlstr);
        		}
            }
        }
		
		//设置grid选中
		$.grid_setFocus({id:_id});
		
	},
	//设置grid获取焦点，以触发快捷键
	grid_setFocus:function(jparam){
		var _id = jparam.id;
		var _containerid = $('#'+_id).datagrid('options').containerid;
		var _gd = $('#'+_containerid).find('div[class="panel datagrid"]');
		_gd.focus();
	},
	//可编辑grid：删除航
	grid_editor_remove:function(jparam){
		var _id = jparam.id;
		var _delid = jparam.delid;
		var _idarr = [];
		if(_delid){
			_idarr = _delid.split(',');
		}
		var _selindex = null;
		var _idField = $('#'+_id).datagrid('options').idField;
		if(_delid){
			 var rows = $('#'+_id).datagrid('getRows');
			 for(var i=rows.length-1;i>-1;i--){
				 var row = rows[i];
				 if(_idarr.contains(row[_idField])){
					 if ($.grid_editor_ending({id:_id})){
					    $('#'+_id).datagrid('deleteRow', i);
					 }else{
						$.grid_editor_cancel({id:_id});
					    $('#'+_id).datagrid('deleteRow', i);
					 }
					 $("#"+_id).datagrid("options").selectrowindex = -1;
				 }
			 }
			 
		}else{
			_selindex = $("#"+_id).datagrid("options").selectrowindex;
			if (-1 == _selindex){return;}
			if ($.grid_editor_ending({id:_id})){
			    $('#'+_id).datagrid('deleteRow', _selindex);
			}else{
				$.grid_editor_cancel({id:_id});
			    $('#'+_id).datagrid('deleteRow', _selindex);
			}
			$("#"+_id).datagrid("options").selectrowindex = -1;
		}
	},
	//可编辑grid：删除所有行
	grid_editor_removeAll:function(jparam){
		var _id = jparam.id;
		var rows = $('#'+_id).datagrid('getRows');
		for(var i=rows.length-1;i>-1;i--){
			if ($.grid_editor_ending({id:_id})){
			    $('#'+_id).datagrid('deleteRow', i);
			}else{
				$.grid_editor_cancel({id:_id});
			    $('#'+_id).datagrid('deleteRow', i);
			}
		}
		$("#"+_id).datagrid("options").selectrowindex = -1;
	},
	//可编辑grid：撤销修改
	grid_editor_reject:function(jparam){
		var _id = jparam.id;
//		_handler_grid_toolbar_reject(_id);
		$('#'+_id).datagrid('rejectChanges');
	},
	//可编辑grid：获取改变的内容
	grid_editor_getchanges:function(jparam){
		var _id = jparam.id;
		var rows = $('#'+_id).datagrid('getChanges');
		return rows;
	},
	grid_enableEdit:function(jparam){
		var _id = jparam.id;
		$("#"+_id).datagrid("options").enableedit = true;
	},
	grid_disableEdit:function(jparam){
		var _id = jparam.id;
		$("#"+_id).datagrid("options").enableedit = false;
	},
	//聚焦
	grid_editor_setFocus:function(jparam){
		var _id = jparam.id;
		var _field = jparam.field;
		
		var _editrowindex = $("#"+_id).datagrid("options").editrowindex;
		if(null!=_editrowindex){
			var editors = $('#'+_id).datagrid('getEditors', _editrowindex);
			for(var i=0;i<editors.length;i++){
				var _ed = editors[i];
				if(null==_field||""==_field){
					if(0==i){
						if($(_ed.target).find('input.inputpop_input').length>0){
				        	$(_ed.target).find('input.inputpop_input').focus();
				        	$(_ed.target).find('input.inputpop_input').select();
				        }else{
				        	$(_ed.target).focus();
				        	$(_ed.target).select();
				        }
			        	break;
					}
				}else{
					if(_field==_ed.field){
						if($(_ed.target).find('input.inputpop_input').length>0){
				        	$(_ed.target).find('input.inputpop_input').focus();
				        	$(_ed.target).find('input.inputpop_input').select();
				        }else{
				        	$(_ed.target).focus();
				        	$(_ed.target).select();
				        }
			        	break;
					}
				}
			}
//			var _v = _data[ed.field];
//        	if(0==_v||'0'==_v||''==_v||_v){
//        		if("inputpop"==ed.type){
//        			$(ed.target).parent().find('input.inputpop_input').val(_v+'');
//        		//	$(ed.target).parent().find('input.inputpop_hidden_name').val(_v.show);
//        		//	$(ed.target).parent().find('input.inputpop_hidden_value').val(_v.hidden);
//	        	}else{
//	        		$(ed.target).val(_v+'');
//	        	}
		}
		
	},
	//返回第几行的行对象
	grid_getRow:function(jparam){
		var _id = jparam.id;
		var _rowIndex = jparam.rowIndex;
		var rows = $('#'+_id).datagrid('getRows');
		var row = rows[_rowIndex];
		
		var cols = $.grid_getColums({id:_id});
		
		for(var j=0;j<cols.length;j++){
			var att = cols[j];
			if(!row[att]){
				row[att] = '';
			}
		}
		return row;
	},
	//返回所有行对象
	grid_getRows:function(jparam){
		var _id = jparam.id;
		var rows = $('#'+_id).datagrid('getRows');
		var cols = $.grid_getColums({id:_id});
		for(var i=0;i<rows.length;i++){
			var row = rows[i];
			for(var j=0;j<cols.length;j++){
				var att = cols[j];
				if(null==row[att]){
					row[att] = '';
				}
			}
		}
		return rows;
	},
	//获取所有的选中行，返回选中行数组
	grid_getSelections:function(jparam){
		var _id = jparam.id;
//		_handler_grid_toolbar_endEditing(_id);
		var rows = $("#"+_id).datagrid("getSelections");
		rows = $.grid_formatDatas({id:_id,data:rows});
		return rows;
	},
	//返回选中的单行
	grid_getSelected:function(jparam){
		var rows = $.grid_getSelections(jparam);
		var row = {};
		if(rows.length>0){
			row = rows[rows.length-1];
		}
		return row;
//		var _id = jparam.id;
////		_handler_grid_toolbar_endEditing(_id);
//		var selectedrow = $("#"+_id).datagrid("getSelected");
//		selectedrow = $.grid_formatData({id:_id,data:selectedrow});
//		return selectedrow;
	},
	//放回当前正在编辑的行的行号
	grid_getEditRowIndex:function(jparam){
		var _id = jparam.id;
		var _editrowindex = $("#"+_id).datagrid("options").editrowindex;
		return _editrowindex;
	},
	//设置选中
	grid_setSelect:function(jparam){
		var _id = jparam.id;
		var _ids = jparam.ids?jparam.ids:'';
		var _rowIndex = jparam.rowIndex;
		
		var _idField = jparam.idField?jparam.idField:null;
		if(!_idField){
			_idField = $('#'+_id).datagrid('options').idField;
		}
		var rows = $('#'+_id).datagrid('getRows');
		for(var i=0;i<rows.length;i++){
			var row = rows[i];
			if(-1!=_ids.indexOf(row[_idField])){
				$("#"+_id).datagrid("selectRow",i);
			}
		}
		if(_rowIndex){
			_rowIndex = _rowIndex +'';
			var riArr = _rowIndex.split(',');
			for(var i=0;i<riArr.length;i++){
				var _ri = riArr[i];
				$("#"+_id).datagrid("selectRow",_ri);
			}
		}
	},
	//设置选中
	grid_setSelectAll:function(jparam){
		var _id = jparam.id;
		var _idField = jparam.idField?jparam.idField:null;
		if(!_idField){
			_idField = $('#'+_id).datagrid('options').idField;
		}
		var rows = $('#'+_id).datagrid('getRows');
		for(var i=0;i<rows.length;i++){
			$("#"+_id).datagrid("selectRow",i);
		}
	},
	//获取勾选的行
	grid_getChecked:function(jparam){
		var _id = jparam.id;
//		_handler_grid_toolbar_endEditing(_id);
		var checkedItems = $('#'+_id).datagrid('getChecked');
		return checkedItems;
	},
	//设置选中行
	grid_setChecked:function(jparam){
		var _id = jparam.id;
		var _ids = jparam.ids;
		//var _idField = jparam.idField;
		var _idField = $('#'+_id).datagrid('options').idField;
		var rows = $.grid_getRows({id:_id});
		for(var i=0;i<rows.length;i++){
			var row = rows[i];
			if(-1!=_ids.indexOf(row[_idField])){
				$("#"+_id).datagrid("checkRow",i);
			}
		}
	},
	//设置全部不选
	grid_uncheckAll:function(jparam){
		var _id = jparam.id;
		$("#"+_id).datagrid("uncheckAll");
	},
	//获取grid的所有列，如果是复杂表头，则复杂 表头的colspan>1的不与计入
	grid_getColums:function(jparam){
		var cols = [];
		var _id = jparam.id;
		var options = $('#'+_id).datagrid('options');
		for(var i=0;i<options.columns.length;i++){
			for(var j=0;j<options.columns[i].length;j++){
				var col = options.columns[i][j];
				if(1==col.colspan){
					cols.push(col.field);
				}
			}
		}
		return cols;
	},
	
	//格式化行数据
	grid_formatData:function (jparam){
		var _id = jparam.id;
		var _row = jparam.data;
		var _cols = $.grid_getColums({id:_id});
		var tmpRow = new Object();
		for(var j=0;j<_cols.length;j++){
			var att = _cols[j];
			var str = _row[att];
			tmpRow[att] = $.grid_getCellData(str);
//			if(str){
//				tmpRow[att] = str;
//			}else{
//				tmpRow[att] = '';
//			}
		}
		return tmpRow;
	},
	/**
	 * 格式化解析grid的数据
	 */
	grid_formatDatas:function (jparam){
		var _id = jparam.id;
		var _rows = jparam.data;
		var _cols = $.grid_getColums({id:_id});
		var tmpRows = [];
		for(var i=0;i<_rows.length;i++){
			var _row = _rows[i];
			var tmpRow = new Object();
			for(var j=0;j<_cols.length;j++){
				var att = _cols[j];
				var str = _row[att];
				tmpRow[att] = $.grid_getCellData(str);
//				if(str){
//					tmpRow[att] = str;
//				}else{
//					tmpRow[att] = '';
//				}
			}
			tmpRows.push(tmpRow);
		}
		return tmpRows;
	},
	//格式化并读取单元格的数据，对于特殊格式的单元格数据解析均在此处处理
	grid_getCellData:function(str){
		if(0!=str&&'0'!=str&&!str){
			str = '';
		}else{
			str = str+"";
			if(-1!=str.indexOf('<input type="checkbox"')){
				if(-1!=str.indexOf('checked')){
					str = '1';
				}else{
					str = '0';
				}
			}
		}
		return str;
	},
	grid_getAllRows:function(jparam){
		var _id = jparam.id;
		var rows = $('#'+_gridid).datagrid('getData').rows;
		return rows;
	},
	//读取grid所有数据
	grid_getData:function(jparam){
		var _id = jparam.id;
		var jrows = {};
		var cols = $.grid_getColums({id:_id});
		//1、完成编辑
		var selectedrow = $("#"+_id).datagrid("getSelected");
        var rowIndex = $("#"+_id).datagrid("getRowIndex", selectedrow);
		$('#'+_id).datagrid('endEdit',rowIndex);
		 
		//2、读取数据
		var allrows = $('#'+_id).datagrid('getRows');
		
		var insertrows = $('#'+_id).datagrid('getChanges','inserted');
		var updaterows = $('#'+_id).datagrid('getChanges','updated');
		var deleterows = $('#'+_id).datagrid('getChanges','deleted');
		
		//原所有行
		if(allrows.length>0){
			var tmpAllrows = [];
			for(var i=0;i<allrows.length;i++){
				var tmpRow = new Object();
				var row = allrows[i];
				for(var j=0;j<cols.length;j++){
					var att = cols[j];
					var str = row[att];
					tmpRow[att] = $.grid_getCellData(str);
//					if(str){
//						tmpRow[att] = str;
//					}else{
//						tmpRow[att] = '';
//					}
				}
				tmpAllrows.push(tmpRow);
			}
			jrows.allrows = tmpAllrows;
		}else{
			jrows.allrows = [];
		}
		
		
		//新增的行
	  	 if (insertrows.length>0) {
	  		var tmpAllrows = [];
	  		for(var i=0;i<insertrows.length;i++){
	  			var tmpRow = new Object();
				var row = insertrows[i];
				for(var j=0;j<cols.length;j++){
					var att = cols[j];
					var str = row[att];
					tmpRow[att] = $.grid_getCellData(str);
//					if(str){
//						tmpRow[att] = str;
//					}else{
//						tmpRow[att] = '';
//					}
				}
				tmpAllrows.push(tmpRow);
			}
	  		jrows.insertrows = tmpAllrows;
	  	 }else{
			jrows.insertrows = [];
	  	 }
		//修改的行
	  	 if (updaterows.length>0) {
	  		var tmpAllrows = [];
	  		for(var i=0;i<updaterows.length;i++){
	  			var tmpRow = new Object();
				var row = updaterows[i];
				for(var j=0;j<cols.length;j++){
					var att = cols[j];
					var str = row[att];
					tmpRow[att] = $.grid_getCellData(str);
//					if(str){
//						tmpRow[att] = str;
//					}else{
//						tmpRow[att] = '';
//					}
				}
				tmpAllrows.push(tmpRow);
			}
	  		jrows.updaterows = tmpAllrows;
	  	 }else{
			jrows.updaterows = [];
	  	 }
	  	//删除的行
	  	 if (deleterows.length>0) {
	  		var tmpAllrows = [];
	  		for(var i=0;i<deleterows.length;i++){
	  			var tmpRow = new Object();
				var row = deleterows[i];
				for(var j=0;j<cols.length;j++){
					var att = cols[j];
					var str = row[att];
					tmpRow[att] = $.grid_getCellData(str);
//					if(str){
//						tmpRow[att] = str;
//					}else{
//						tmpRow[att] = '';
//					}
				}
				tmpAllrows.push(tmpRow);
			}
	  		jrows.deleterows = tmpAllrows;
	  	 }else{
			jrows.deleterows = [];
	  	 } 	
	  	
	  	 //完成提交
	  //$('#'+_gridid).datagrid('acceptChanges');
	  	return jrows;
	},
	
	//将rows行数据转换为列数据
	grid_getDataTypeCol:function(rows,splitstr){
		if(!splitstr){
			splitstr = ',';
		}
		var cols = new Object();
		var row0 = rows[0];
		for(var att in row0){
			cols[att] = [];
		}
		for(var i=0;i<rows.length;i++){
			var row = rows[i];
			for(var att in row){
				if(cols[att]){
					var strtmp = $.grid_getCellData(row[att]);
					cols[att].push(strtmp);
				}else{
					cols[att] = [];
					cols[att].push('');
				}
			}
		}
		var res = new Object();
		for(var att in row0){
			res[att] = cols[att].join(splitstr);
		}
		return $.json2str(res);
	},
	grid_setData:function(jparam){
		var _id = jparam.id;
		var _data = jparam.data;
		var _rowIndex = jparam.rowIndex;
//		if(!_rowIndex){
//			var _opts = $("#"+_id).datagrid("options");
//			var _editrowindex = _opts.editrowindex;
//			_rowIndex = _editrowindex;
//		}
//		if(-1==_rowIndex){
//			return false;
//		}
		
		if(0!=_rowIndex&&!_rowIndex){
			var _opts = $("#"+_id).datagrid("options");
			_rowIndex = _opts.selectrowindex;
		}
		if(-1==_rowIndex){
			var selectedrow = $("#"+_id).datagrid("getSelected");
			if(selectedrow){
				_rowIndex = $("#"+_id).datagrid("getRowIndex", selectedrow);
			}
		}
		
		if(-1==_rowIndex){
			return false;
		}
		
		
//		var selectedrow = $("#"+_id).datagrid("getSelected");
//        var rowIndex = $("#"+_id).datagrid("getRowIndex", selectedrow);
        
//        var edname = "";
		var edname = [];
        //首先改变编辑器的值
        var editors = $('#'+_id).datagrid('getEditors', _rowIndex);
        for(var i=0;i<editors.length;i++){
        	var ed = editors[i];
        	var _v = _data[ed.field];
        	if(0==_v||'0'==_v||''==_v||_v){
        		if("inputpop"==ed.type){
        			$(ed.target).parent().find('input.inputpop_input').val(_v+'');
        		//	$(ed.target).parent().find('input.inputpop_hidden_name').val(_v.show);
        		//	$(ed.target).parent().find('input.inputpop_hidden_value').val(_v.hidden);
	        	}else{
	        		$(ed.target).val(_v+'');
	        	}
        		$('#'+_id).datagrid('getData').rows[_rowIndex][ed.field]=_data[ed.field]+'';
        	}
//        	edname+=ed.field+",";
        	edname.push(ed.field);

        }
      //然后改变非编辑器的值
     //   $('#'+_id).datagrid('endEdit', rowIndex); 
     //   alert('edname='+edname+'\n    data='+$.json2str(_data));
        
        var _div = $('#'+_id).datagrid('getPanel').find('div.datagrid-body')[1];
        for(var att in _data){
        	if(!edname.contains(att)){
        		if(0==_data[att]||'0'==_data[att]||''==_data[att]||_data[att]){
	        		$('#'+_id).datagrid('getData').rows[_rowIndex][att]=_data[att]+'';
	        		
	                var _cnt = $(_div).find('table tbody tr:eq('+_rowIndex+') td[field="'+att+'"] div');
	                $(_cnt).text(_data[att]+'');
	        	}
	        }
        }
       
        
        
        
//        tr.each(function(){   
//        	var td = $(this).children(\'td[field=\"name\"]\');   
//        });           
//        $('#'+_id).datagrid('updateRow', $('#'+_id).datagrid('getData').rows[_rowIndex]);
        
//        $('#'+_id).datagrid('refreshRow', _rowIndex);
//    	$.grid_editor_beginEdit({id:_id,type:'edit',rowIndex:_rowIndex});
        
	},
	grid_merge:function(id,mfid){
		if(!mfid||""==mfid){
			return false;
		}
		var colarr = mfid.split(',');
		var rows = $('#'+id).datagrid('getRows');
		var arr = [];
		
//		$('#'+id).datagrid('mergeCells',{
//            index:0,
//            field:'biztype',
//            rowspan:2,
//            colspan:null
//        });
//		
//		return false;
		var isAllSame = false;	//是否所有字段都和下一个相同
		var startRow = 0;		//开始的行号	
		var rowspan = 1;		//占据的行数
		
		for(var i=0;i<rows.length-1;i++){
			var issame = true;
			for(var j=0;j<colarr.length;j++){
				var colname = colarr[j];
				if(rows[i][colname]!=rows[i+1][colname]){
					issame = false;
				}
			}
			
			if(!issame){
//				alert('hebing  startRow='+startRow+'   rowspan='+rowspan);
				for(var j=0;j<colarr.length;j++){
					$('#'+id).datagrid('mergeCells',{
	                    index:startRow,
	                    field:colarr[j],
	                    rowspan:rowspan,
	                    colspan:null
	                });
				}
				startRow = i+1;
				rowspan = 1;
			}else{
				rowspan++;
				if(i==rows.length-2){
					//如果是最后一行，同时当前还是true
					for(var j=0;j<colarr.length;j++){
						$('#'+id).datagrid('mergeCells',{
		                    index:startRow,
		                    field:colarr[j],
		                    rowspan:rowspan,
		                    colspan:null
		                });
					}
				}
			}
			
			
			
		}
	},
	/**	grid_mergeCellsByField
	 * EasyUI DataGrid根据字段动态合并单元格
	 * @param tableID 要合并table的id
	 * @param colList 要合并的列,用逗号分隔(例如："name,department,office");
	 */
	grid_merge2:function(id,mfid){
		if(!mfid||""==mfid){
			return false;
		}
        var ColArray = mfid.split(",");
        var tTable = $('#'+id);
        var TableRowCnts = tTable.datagrid("getRows").length;
        var tmpA;
        var tmpB;
        var PerTxt = "";
        var CurTxt = "";
        var alertStr = "";
        for (j=ColArray.length-1;j>=0 ;j-- ){
            Perxt="";
            tmpA=1;
            tmpB=0;
            
            for (i=0;i<=TableRowCnts ;i++ ){
                if (i==TableRowCnts){
                    CurTxt="";
                }else{
                    CurTxt=tTable.datagrid("getRows")[i][ColArray[j]];
                }
                if (PerTxt==CurTxt){
                    tmpA+=1;
                }else{
                    tmpB+=tmpA;
                    //alert('colindex='+(i-tmpA))
                    tTable.datagrid('mergeCells',{
                        index:i-tmpA,
                        field:ColArray[j],
                        rowspan:tmpA,
                        colspan:null
                    });
                    tmpA=1;
                }
                PerTxt=CurTxt;
            }
        }
	},
	// http://blog.csdn.net/core_star/article/details/8928111
//	参数说明
//	grid：        easyUI的datagrid对象
//	refCols        合并参考列数组，及这些列都相等则合并rowFildNames指定的列
//	rowFildNames： 和并列的field属性值及要合并的列数组
//
//	示例：mergeGridColCells($('#serviceTypeTable'),['serviceTypeId','areaId'],['areaName']);
	grid_merge23:function(grid,refCols,rowFildNames)  
    {  
           var rows=grid.datagrid('getRows' );  
           //alert(rows.length);  
           //alert(rows[1][rowFildName]);  
           var flag=false ;  
           var startIndex=0;  
           var endIndex=0;  
           if(rows.length< 1)  
          {  
                 return;  
          }  
          $.each(rows, function(i,row){  
            $.each(refCols, function(j,refCol){  
                  if(row[refCol]!=rows[startIndex][refCol])  
                  {  
                        flag= false;  
                        return false ;  
                  }  
                  else  
                  {  
                        flag= true;  
                  }  
            });  
                //if(row[rowFildName]==rows[startIndex][rowFildName])  
                if(flag)  
                {  
                      endIndex=i;  
                }  
                 else  
                {  
                       $.each(rowFildNames, function(k,rowFildName){  
                             grid.datagrid( 'mergeCells',{  
                                  index: startIndex,  
                                  field: rowFildName,  
                                  rowspan: endIndex -startIndex+1,  
                                  colspan: null  
                            });  
                       });  
                       
                      startIndex=i;  
                      endIndex=i;  
                }  
          });  
          $.each(rowFildNames, function(k,rowFildName){  
                 grid.datagrid( 'mergeCells',{  
                            index: startIndex,  
                            field: rowFildName,  
                            rowspan: endIndex -startIndex+1,  
                            colspan: null  
                      });  
        });  
    },
	//grid导出到EXCEL
	grid_export_excel:function(jparam){
		var _gridcode = jparam.gridcode;
//		var _captionurl = jparam.captionurl;
//		_captionurl = $.encode(_captionurl);
		var _gridid = jparam.gridid;
		var _epclass = 'grid';										//控件类型
		var _epformat = jparam.epformat?jparam.epformat:'excel';	//导出格式	
		var _eptype = jparam.eptype?jparam.eptype:'0';				//导出方式：0-导出当前页    1-导出全部
		var _mergetype = jparam.mergetype?jparam.mergetype:'0';		//合并方式：0-支持合并  1-不合并
		var _options =  $('#'+_gridid).datagrid("options");
		var _pageoptions = null;
		if(null!=$('#'+_gridid).datagrid('getPager')&&null!=$('#'+_gridid).datagrid('getPager').data("pagination")){
			_pageoptions = $('#'+_gridid).datagrid('getPager').data("pagination").options;
		}
		
		var _url = _options.url;
		var _queryParams = _options.queryParams;
		
		if(_options.footer.length>0){
			var strfooter = $.json2str(_options.footer);
			strfooter = strfooter.replace(/\'/ig,"\'").replace(/\"/ig,"\'");
			strfooter = encodeURI(encodeURI(strfooter));
			_queryParams.footer = strfooter;
		}
//		if(!_queryParams.orderbyfield){
//			_queryParams.orderbyfield = _idField;
//		}
		
		//处理分页，用于导出当页或导出全部页
		var _rows = 0;
		var _page = 0;
		var _totalSize = 0;
		if(null!=_pageoptions){
			_rows = _pageoptions.pageSize;
			_page = _pageoptions.pageNumber;
			_totalSize = _pageoptions.total;
		}
		
		//如果是导出全部
		if('1'==_eptype){
			_rows = '1000000000';
			_page = '1';
		}
		var _data = [
		             {name:'epclass',value:_epclass},
		             {name:'h_action_type',value:'export'},			//用于baseaction中对请求进行判断
		             {name:'epformat',value:_epformat},
		             {name:'eptype',value:_eptype},
		             {name:'mergetype',value:_mergetype},
		             {name:'gridid',value:_gridid},
		             {name:'gridcode',value:_gridcode},
//		             {name:'captionurl',value:_captionurl},
		             {name:"rows",value:_rows},
		             {name:"page",value:_page},
		             {name:"totalSize",value:_totalSize}
			     	];
		for(var att in _queryParams){
			_data.push({name:att,value:_queryParams[att]?_queryParams[att]:""});
		}
		var _urlparamarr = [];
		for(var i=0;i<_data.length;i++){
			var pa = _data[i];
			_urlparamarr.push(pa.name+"="+pa.value);
		}
		_url += "&"+_urlparamarr.join('&');
		_url = $.base()+"/"+_url;
//		alert('_url='+_url)
		$.download({url:_url});
		//window.open(_url);
		
	},
	//导入excel
	grid_import:function(jparam){
		var _gridcode = jparam.gridcode;
//		var _captionurl = jparam.captionurl;
//		_captionurl = $.encode(_captionurl);
		var _gridid = jparam.gridid;
		//excel导入上传文件存放的目录
		jparam.catalogid='default';
		//1、上传
		$.upload({
			upload_url:'wdk?action=wdk.public&method=attachment_upload&ajaxparam='+new Date().getTime(),
			file_types :'*.xls;*.xlsx',
			catalogid:jparam.catalogid,
			upload_limit:1,
			callback:grid_import_callback,
			param:jparam
		});
	},
	grid_import_callback:function(jparam){
		//2、等待
		$.wait_open();
		var fieldids = jparam.fieldids;
		var _data = {
						catalogid:jparam.catalogid,
						fieldids:fieldids,
						gridcode:jparam.gridcode,
						captionurl:$.encode(jparam.captionurl)
					};
		$.cuajax({
		  	url:'wdk?action=wdk.public&method=grid_import&ajaxparam='+new Date().getTime(),
			method:"post", 
			timeout:WDK_Timeout,
			data:_data,   
			success:function(result) {
				var jres = eval('('+result+')');
				$.grid_reload({id:jparam.gridid});
//				alert(jres.desc);
				$.getRoot().$.messager.alert('信息提示',jres.desc);
				$.wait_close();
			},
			error:function(result){
//				alert('网络错误！result='+result);
				$.getRoot().$.messager.alert('信息提示','网络错误：'+result,'error');
				$.wait_close();
			}
		});
		//3、返回结果
	},
	/*********************************************8
	 * 				生成工具条控件
	 * 
	 * 	功能说明：
	 * 
	 * 	参数说明：
	 *********************************************/
	//顶层toolbar
	toptoolbar:function(jparam){
		var _id = jparam.id?jparam.id:"";
		var _data = jparam.data;
		
		var idarr = [];
		var arr = [];
		arr.push('<div style="padding:0px;white-space: nowrap; word-break: keep-all;height:100%;" class="frame_toolbar">');
		//构建第一层菜单
		for(var i=0;i<_data.length;i++){
			var jt = _data[i];
			if(!jt.parentid){
				//看看是否有子节点
				arr.push('<a id="menu_'+jt.id+'" style="color:#000000;" href="#" >'+jt.name+'</a>');
				var hasChild = false;
				for(var j=0;j<_data.length;j++){
					if(_data[j].parentid==jt.id){
						hasChild = true;
						break;
					}
				}
				jt.hasChild = hasChild;
				idarr.push(jt);
			}
		}
	//	arr.push('<span id="toptoolbar_info" style="position:fixed;right:10px;padding-top:5px;">放置关闭按钮和用户信息</span>');
		arr.push('</div>');
		$("#"+_id).append(arr.join(''));
		
		
		//迭代构建下面几层
		for(var i=0;i<_data.length;i++){
			var jt = _data[i];
			if(!jt.parentid){
				$.toptoolbar_iterator(_id,_data,jt);
			}
		}
		//赋值easyui属性
		for(var i=0;i<idarr.length;i++){
			if(idarr[i].hasChild){
				$('#menu_'+idarr[i].id).menubutton({menu:'#child_'+idarr[i].id,iconCls:idarr[i].icon});
			}else{
				$('#menu_'+idarr[i].id).menubutton({iconCls:idarr[i].icon});
			}
		}
	},
	//迭代工具栏
	toptoolbar_iterator:function(_id,_data,parent){
		for(var i=0;i<_data.length;i++){
			var jt = _data[i];
			if(jt.parentid==parent.id){
				//如果父节点为一级
				if(!parent.parentid){
					if($("#child_"+parent.id).length<1){
						$("#"+_id).append('<div id="child_'+parent.id+'" style="width:150px;"></div>');
					}
					if("menu-split"==jt.type){
						//如果是分隔符，则添加分隔符号
						$("#child_"+parent.id).append('<div class="menu-sep"></div>');
					}else if('menu-content'==jt.type){
						//如果是菜单内容体
						$("#child_"+parent.id).attr('class','menu-content');
						$("#child_"+parent.id).css('background','#f0f0f0');
						$("#child_"+parent.id).css('padding','10px');
						$("#child_"+parent.id).css('text-align','left');
						$("#child_"+parent.id).css('width','300px');
						$("#child_"+parent.id).append(jt.html);
					}else{
						//判断当前节点是否有子节点
						var hasChild = false;
						for(var j=0;j<_data.length;j++){
							if(_data[j].parentid==jt.id){
								hasChild = true;
								break;
							}
						}
						if(hasChild){
							$("#child_"+parent.id).append('<div id="sub_'+jt.id+'"><span>'+jt.name+'</span></div>');
							$.toptoolbar_iterator(_id,_data,jt);
						}else{
							$("#child_"+parent.id).append('<div data-options="iconCls:\''+jt.icon+'\'" onclick="_handler_toolbar_onclick(\''+jt.id+'\')">'+jt.name+'</div>');
						}
					}
				}else{
					//如果父节点不是一级
					if($("#sub_"+parent.id).length<1){
						return;
					}
					if($("#sub_sub_"+parent.id).length<1){
						$("#sub_"+parent.id).append('<div id="sub_sub_'+parent.id+'" style="width:150px;"></div>');
					}
					if("_split"==jt.id){
						//如果是分隔符，则添加分隔符号
						$("#sub_sub_"+parent.id).append('<div class="menu-sep"></div>');
					}else{
						//判断当前节点是否有子节点
						var hasChild = false;
						for(var j=0;j<_data.length;j++){
							if(_data[j].parentid==jt.id){
								hasChild = true;
								break;
							}
						}
						if(hasChild){
							$("#sub_sub_"+parent.id).append('<div id="sub_'+jt.id+'"><span>'+jt.name+'</span></div>');
							$.toptoolbar_iterator(_id,_data,jt);
						}else{
							$("#sub_sub_"+parent.id).append('<div data-options="iconCls:\''+jt.icon+'\'" onclick="_handler_toolbar_onclick(\''+jt.id+'\')">'+jt.name+'</div>');
						}
					}
				}
			}
		}
	},
	
	//初始化button工具条
	toolbar:function(jparam){
		var _id = jparam.id?jparam.id:"";
		var _menucode = jparam.menucode?jparam.menucode:"";
		var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(){};
		
		var _url = "wdk?action=wdk.public&method=button_load&menucode="+_menucode;
		var _jmenu = jparam.data?jparam.data:null;
		
		//var _urlparam = jparam.urlparam?jparam.urlparam:{};
		
		var _queryParams = jparam.queryParams?jparam.queryParams:{};
		var _onClick = jparam.onClick?$.event_getHandler(jparam.onClick):function(){};			//菜单单击回调函数名
		var _onClickStr = $.getFuncName(_onClick);
		var _getData = jparam.getData?$.event_getHandler(jparam.getData):function(){};
		
		if(_jmenu){
			//回写menudata
			if(_getData){
				_getData(_jmenu);
			}
			$("#menu_other_list").html('');
			$("#"+_id).html('');
			
			var arr = [];

			//计算要到第几个才进行隐藏
			var cLen = document.documentElement.clientWidth;
			var tLen = 0;
			var nNum = 0;
			for(var i=0;i<_jmenu.length;i++){
				nNum = i+1;
				var jm = _jmenu[i];
				tLen += $.getTextSize(jm.name).width;
				if(jm.icon){
					tLen += 20;
				}
				//预留下拉区域
				if(tLen>(cLen-300)){
					break;
				}
			}

			//1、添加菜单标签
			//1.1 添加不隐藏部分的菜单标签内容
			arr.push('<table cellspacing="0" cellpadding="0"><tr>');
			for(var i=0;i<nNum;i++){
				var jm = _jmenu[i];
				if("|"!=jm.name){
					arr.push('<td><a id="toolbar_'+jm.id+'" href="javascript:void(0);" '+(_onClickStr?'onclick="'+_onClickStr+'(\'{id:\\\''+jm.id+'\\\',name:\\\''+jm.name+'\\\'}\');return false;"':'return false;')+'>'+jm.name+'</a></td>');
				}else{
					arr.push('<td><div class="datagrid-btn-separator"></div></td>');
				}
			}
			
			if(nNum<_jmenu.length){
				//1.2 添加隐藏的部分的菜单标签内容
				arr.push('<td><a id="menu_other" href="#" ></a></td>');
			}
			arr.push('</tr></table>');
			//添加下拉菜单按钮
			arr.push('<div id="menu_other_list" style="width:100px;">');
			for(var i=nNum;i<_jmenu.length;i++){
				var jm = _jmenu[i];
//					arr.push('	<div id="toolbar_'+jm.id+'" data-options="disabled:'+('true'==jm.disabled?'true':'false')+',iconCls:\''+jm.icon+'\'" '+(_onClickStr?'onclick="if(!this.disabled){'+_onClickStr+'(\'{id:\\\''+jm.id+'\\\',name:\\\''+jm.name+'\\\'}\');return false;}"':'return false;')+'>'+jm.name+'</div>');
				arr.push('	<a id="toolbar_'+jm.id+'"  href="javascript:void(0);" '+(_onClickStr?'onclick="if(!this.disabled){'+_onClickStr+'(\'{id:\\\''+jm.id+'\\\',name:\\\''+jm.name+'\\\'}\');return false;}"':'return false;')+'>'+jm.name+'</a>');
			}
			arr.push('</div>');
			$("#"+_id).html(arr.join(''));
			

			//2、绑定标签至easyui的menubutton
			for(var i=0;i<_jmenu.length;i++){
//				for(var i=0;i<nNum;i++){
				var jm = _jmenu[i];
				$('#toolbar_'+jm.id).linkbutton({ plain:true,iconCls:jm.icon,disabled:'true'==jm.disabled?true:false}); 
			}
			$('#menu_other').menubutton({menu: '#menu_other_list',plain:true,iconCls:'icon-reload'});
			

			_onLoadSuccess(_jmenu);
		}else{
			$.cuajax({
				url: _url,
				method:"post", 
				timeout:WDK_Timeout,
				data:_queryParams,   
				success:function(result) {
					_jmenu = $.str2json(result);
					//回写menudata
					if(_getData){
						_getData(_jmenu);
					}
					$("#menu_other_list").html('');
					$("#"+_id).html('');
					
					var arr = [];
	
					//计算要到第几个才进行隐藏
					var cLen = document.documentElement.clientWidth;
					var tLen = 0;
					var nNum = 0;
					for(var i=0;i<_jmenu.length;i++){
						nNum = i+1;
						var jm = _jmenu[i];
						tLen += $.getTextSize(jm.name).width;
						if(jm.icon){
							tLen += 20;
						}
						//预留下拉区域
						if(tLen>(cLen-300)){
							break;
						}
					}
					//1、添加菜单标签
					//1.1 添加不隐藏部分的菜单标签内容
					arr.push('<table cellspacing="0" cellpadding="0"><tr>');
					for(var i=0;i<nNum;i++){
						var jm = _jmenu[i];
						if("|"!=jm.name){
							arr.push('<td><a id="toolbar_'+jm.id+'" href="javascript:void(0);" '+(_onClickStr?'onclick="'+_onClickStr+'(\'{id:\\\''+jm.id+'\\\',name:\\\''+jm.name+'\\\'}\');return false;"':'return false;')+'>'+jm.name+'</a></td>');
						}else{
							arr.push('<td><div class="datagrid-btn-separator"></div></td>');
						}
					}
					
					if(nNum<_jmenu.length){
						//1.2 添加隐藏的部分的菜单标签内容
						arr.push('<td><a id="menu_other" href="#" ></a></td>');
					}
					arr.push('</tr></table>');
					//添加下拉菜单按钮
					arr.push('<div id="menu_other_list" style="width:100px;">');
					for(var i=nNum;i<_jmenu.length;i++){
						var jm = _jmenu[i];
	//					arr.push('	<div id="toolbar_'+jm.id+'" data-options="disabled:'+('true'==jm.disabled?'true':'false')+',iconCls:\''+jm.icon+'\'" '+(_onClickStr?'onclick="if(!this.disabled){'+_onClickStr+'(\'{id:\\\''+jm.id+'\\\',name:\\\''+jm.name+'\\\'}\');return false;}"':'return false;')+'>'+jm.name+'</div>');
						arr.push('	<a id="toolbar_'+jm.id+'"  href="javascript:void(0);" '+(_onClickStr?'onclick="if(!this.disabled){'+_onClickStr+'(\'{id:\\\''+jm.id+'\\\',name:\\\''+jm.name+'\\\'}\');return false;}"':'return false;')+'>'+jm.name+'</a>');
					}
					arr.push('</div>');
					$("#"+_id).html(arr.join(''));
					
					//2、绑定标签至easyui的menubutton
					for(var i=0;i<_jmenu.length;i++){
	//				for(var i=0;i<nNum;i++){
						var jm = _jmenu[i];
						$('#toolbar_'+jm.id).linkbutton({ plain:true,iconCls:jm.icon,disabled:'true'==jm.disabled?true:false}); 
					}
					$('#menu_other').menubutton({menu: '#menu_other_list',plain:true,iconCls:'icon-reload'});
					
					_onLoadSuccess(_jmenu);
				},
				error:function(result){
	//				alert('网络错误！result='+result);
					$.getRoot().$.messager.alert('信息提示','网络错误：'+result,'error');
				}
			});
		}
	},
	toolbar_disabled:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var otb = $("#toolbar_"+_id)[0];
		if(!otb){
			return;
		}
		var tagname = otb.tagName.toLowerCase();
		if('a'==tagname){
			$('#toolbar_'+_id).linkbutton('disable');
		}else{
			$('#toolbar_'+_id).attr('disabled',true);
		}
	},
	toolbar_enabled:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var otb = $("#toolbar_"+_id)[0];
		if(!otb){
			return;
		}
		var tagname = otb.tagName.toLowerCase();
		if('a'==tagname){
			$('#toolbar_'+_id).linkbutton('enable');
		}else{
			$('#toolbar_'+_id).attr('disabled',false);
		}
		
	},
	//菜单按钮控件
	menubutton:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _plain = (false==jparam.plain)?jparam.plain:true;
		var _menu = jparam.menu?jparam.menu:'';
		var _iconCls = jparam.iconCls?jparam.iconCls:'';
		var _duration = jparam.duration?jparam.duration:100;
		 $('#'+_id).menubutton({
			 plain:_plain,
			 menu:_menu,
			 iconCls:_iconCls,
			 duration:_duration
		 });
	},
	//链接按钮控件
	linkbutton:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _disabled = (true==jparam.disabled)?jparam.disabled:false;
		var _plain = (false==jparam.plain)?jparam.plain:true;
		var _text = jparam.text?jparam.text:'';
		var _iconCls = jparam.iconCls?jparam.iconCls:'';
		 $('#'+_id).linkbutton({
			 disabled:_disabled,
			 plain:_plain,
			 text:_text,
			 iconCls:_iconCls
		 });
	},
	linkbutton_disabled:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var tagname = $('#'+_id)[0].tagName.toLowerCase();
		if('a'==tagname){
			$('#'+_id).linkbutton('disable');
		}else{
			$('#'+_id).attr('disabled',true);
		}
	},
	linkbutton_enabled:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var tagname = $('#'+_id)[0].tagName.toLowerCase();
		if('a'==tagname){
			$('#'+_id).linkbutton('enable');
		}else{
			$('#'+_id).attr('disabled',false);
		}
		
	},
	/*********************************************8
	 * 				日期条控件
	 * 
	 * 	功能说明：
	 * 
	 * 	参数说明：
	 *********************************************/
	//日期控件
	datebox:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _initvalue = jparam.initvalue?jparam.initvalue:"";
		var _required = (true==jparam.required)?jparam.required:false;
		var _editable = (false==jparam.editable)?jparam.editable:true;
		var _missingMessage = jparam.missingMessage?jparam.missingMessage:'该项不能为空';
		var _tipPosition = jparam.tipPosition?jparam.tipPosition:'bottom';
		
		var _panelWidth = jparam.panelWidth?jparam.panelWidth:180;			//下拉日历面板的宽度
		var _panelHeight = jparam.panelHeight?jparam.panelHeight:"auto";	//下拉日历面板的高度
		var _currentText = jparam.currentText?jparam.currentText:"今天";		//当前日期按钮上显示的文字
		var _closeText = jparam.closeText?jparam.closeText:"关闭";			//关闭按钮上显示的文字。
		var _okText = jparam.okText?jparam.okText:"确定";					//确定按钮上显示的文字
		var _disabled = (true==jparam.disabled)?jparam.disabled:false;		//为 true 时禁用该域
		var _strFormatter = jparam.strFormatter?jparam.strFormatter:"yyyy-MM-dd";	//显示样式
		
		

  		var _onHidePanel = jparam.onHidePanel?$.event_getHandler(jparam.onHidePanel):function(){};			//继承自combo，当下拉面板隐藏的时候触发
  		var _onShowPanel = jparam.onShowPanel?$.event_getHandler(jparam.onShowPanel):function(){};			//继承自combo，当下拉面板显示的时候触发
  		var _onChange = jparam.onChange?$.event_getHandler(jparam.onChange):function(newValue, oldValue){};					//继承自combo，当文本域的值改变的时候触发
  		var _onSelect = jparam.onSelect?$.event_getHandler(jparam.onSelect):function(date){};					//当用户选择一个日期时触发

		$('#'+_id).attr('isrequired',_required);
		$('#'+_id).datebox({   
			required:_required,
	        editable:_editable,
			missingMessage:_missingMessage,
			tipPosition:_tipPosition,
			panelWidth:_panelWidth,
			panelHeight:_panelHeight,
			currentText:_currentText,
			closeText:_closeText,
			okText:_okText,
			strFormatter:_strFormatter,
			disabled:_disabled,
			onSelect:function(date){
				_onSelect(date);
			},
			onHidePanel:function(){
				_onHidePanel();
			},
			onShowPanel:function(){
				_onShowPanel();
			},
			onChange:function(newValue, oldValue){
				_onChange(newValue, oldValue);
			},
			formatter:function(date) {  
				var y = date.getFullYear();  
				var m = date.getMonth() + 1;  
				var d = date.getDate();  
				
				var ds = (y+'') +  (m < 10 ? '0' + m : m+'') +  (d < 10 ? '0' + d : d+'');
				var datestr = new DateUtil().formateDate(_strFormatter,ds);
				return datestr;
			},
			parser:function(datestr) { 
				if (datestr) {  
					var date = new DateUtil().parseDate(_strFormatter,datestr);
					return date;  
				} else {  
					return new Date();  
				}
			}
		});
		var dstr = "";
		if(null==_initvalue||""==_initvalue.trim()){
		}else{
			dstr = new DateUtil().formateDate(_strFormatter,_initvalue);
		}
		$('#'+_id).datebox('setValue',dstr);
	},
	datebox_disabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).datebox('disable');
	},
	datebox_enabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).datebox('enable');
	},
	datebox_getValue:function(jparam){
		var _id = jparam.id;
		var _datestr = $('#'+_id).datebox('getValue');
		var _strFormatter = $('#'+_id).datebox('options').strFormatter;
		var _value = new DateUtil().getDateValue(_strFormatter,_datestr);
		return _value;
	},
	datebox_setValue:function(jparam){
		var _id = jparam.id;
		var _value = jparam.value;
		var _strFormatter = $('#'+_id).datebox('options').strFormatter;
		var dstr = new DateUtil().formateDate(_strFormatter,_value);
		$('#'+_id).datebox('setValue',dstr);
		$('#'+_id).datebox('validate');
		return _value;
	},
	datebox_clear:function(jparam){
		var _id = jparam.id;
		$.datebox_setValue({id:_id,value:''});
	},
	//日期时间控件
	datetimebox:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _initvalue = jparam.initvalue?jparam.initvalue:"";
		var _required = (true==jparam.required)?jparam.required:false;
		var _editable = (false==jparam.editable)?jparam.editable:true;
		var _missingMessage = jparam.missingMessage?jparam.missingMessage:'该项不能为空';
		var _tipPosition = jparam.tipPosition?jparam.tipPosition:'bottom';
		
		var _panelWidth = jparam.panelWidth?jparam.panelWidth:180;			//下拉日历面板的宽度
		var _panelHeight = jparam.panelHeight?jparam.panelHeight:"auto";	//下拉日历面板的高度
		var _currentText = jparam.currentText?jparam.currentText:"今天";		//当前日期按钮上显示的文字
		var _closeText = jparam.closeText?jparam.closeText:"关闭";			//关闭按钮上显示的文字。
		var _okText = jparam.okText?jparam.okText:"确定";					//确定按钮上显示的文字
		var _disabled = (true==jparam.disabled)?jparam.disabled:false;		//为 true 时禁用该域
		
		var _showSeconds = (false==jparam.showSeconds)?jparam.showSeconds:true;
		var _strFormatter = jparam.strFormatter?jparam.strFormatter:"yyyy-MM-dd HH:mm:ss";	//显示样式
		
  		var _onHidePanel = jparam.onHidePanel?$.event_getHandler(jparam.onHidePanel):function(){};			//继承自combo，当下拉面板隐藏的时候触发
  		var _onShowPanel = jparam.onShowPanel?$.event_getHandler(jparam.onShowPanel):function(){};			//继承自combo，当下拉面板显示的时候触发
  		var _onChange = jparam.onChange?$.event_getHandler(jparam.onChange):function(newValue, oldValue){};					//继承自combo，当文本域的值改变的时候触发
  		var _onSelect = jparam.onSelect?$.event_getHandler(jparam.onSelect):function(date){};					//当用户选择一个日期时触发
  		
  		
		$('#'+_id).attr('isrequired',_required);
		$('#'+_id).datetimebox({
			showSeconds:_showSeconds,
			required:_required,
	        editable:_editable,
			missingMessage:_missingMessage,
			tipPosition:_tipPosition,
			strFormatter:_strFormatter,
			panelWidth:_panelWidth,
			panelHeight:_panelHeight,
			currentText:_currentText,
			closeText:_closeText,
			okText:_okText,
			disabled:_disabled,
			onSelect:function(date){
				_onSelect(date);
			},
			onHidePanel:function(){
				_onHidePanel();
			},
			onShowPanel:function(){
				_onShowPanel();
			},
			onChange:function(newValue, oldValue){
				_onChange(newValue, oldValue);
			},
			formatter:function(date) {  
				var y = date.getFullYear();  
				var m = date.getMonth() + 1;  
				var d = date.getDate();  
				
				var h = date.getHours();
				var mm = date.getMinutes();  
				var s = date.getSeconds();
				var ds = (y+'') + ( m < 10 ? '0' + m : m+'') +(d < 10 ? '0' + d : d+'')+ (h < 10 ? '0' + h : h+'')+ (mm < 10 ? '0' + mm : mm+'')+ (s < 10 ? '0' + s : s+'');  
				var datestr = new DateUtil().formateDateTime(_strFormatter,ds);
				return datestr;
			},
			parser:function(datestr) {  
				if (datestr) {  
					var date = new DateUtil().parseDateTime(_strFormatter,datestr);
					return date;  
				} else {  
					return new Date();  
				}
			}
		});  
//		var arr = null;
//		if(_initvalue&&''!=_initvalue){
//			arr = _initvalue.split(' ');
//		}
//		if(!arr||arr.length>1){
//		}else{
//			_initvalue = _initvalue.substring(0,4)+"-"+_initvalue.substring(4,6)+"-"+_initvalue.substring(6,8)+" "+_initvalue.substring(8,10)+":"+_initvalue.substring(10,12)+":"+_initvalue.substring(12,14);  
//		}
		var dstr = new DateUtil().formateDateTime(_strFormatter,_initvalue);
		$('#'+_id).datetimebox('setValue',dstr);
	},
	
//	var y = date.getFullYear();  
//	var m = date.getMonth() + 1;  
//	var d = date.getDate();  
//	var h = date.getHours();
//	var mm = date.getMinutes();  
//	var s = date.getSeconds();
//	return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d)+ " "+(h < 10 ? '0' + h : h)+ ":"+(mm < 10 ? '0' + mm : mm+ ":"+(s < 10 ? '0' + s : s));  

	
	datetimebox_disabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).datetimebox('disable');
	},
	datetimebox_enabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).datetimebox('enable');
	},
	
	datetimebox_getText:function(jparam){
		var _id = jparam.id;
		var _datestr = $('#'+_id).datetimebox('getValue');
		return _datestr;
	},
	datetimebox_getValue:function(jparam){
		var _id = jparam.id;
		var _datestr = $('#'+_id).datetimebox('getValue');
		var _strFormatter = $('#'+_id).datetimebox('options').strFormatter;
		var _value = new DateUtil().getDateTimeValue(_strFormatter,_datestr);
		return _value;
	},
	datetimebox_setValue:function(jparam){
		var _id = jparam.id;
		var _value = jparam.value;
		var _strFormatter = $('#'+_id).datetimebox('options').strFormatter;
		var dstr = new DateUtil().formateDateTime(_strFormatter,_value);
		$('#'+_id).datetimebox('setValue',dstr);
		$('#'+_id).datetimebox('validate');
		return _value;
	},
	datetimebox_clear:function(jparam){
		var _id = jparam.id;
		$.datetimebox_setValue({id:_id,value:''});
	},
	
	
	//属性菜单控件
	accordion_tree:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _url = jparam.url?jparam.url:'';											//树数据获取地址
		var _data = jparam.data?jparam.data:[];
		var _method = jparam.method?jparam.method:'post';								//http请求方式
		var _animate = (true==jparam.animate)?jparam.animate:false;						//是否显示折叠动画效果
		var _checkbox = (true==jparam.checkbox)?jparam.checkbox:false;					//是否显示复选框
		var _cascadeCheck = (false==jparam.cascadeCheck)?jparam.cascadeCheck:true;		//是否级联检查checkbox
		var _onlyLeafCheck = (true==jparam.onlyLeafCheck)?jparam.onlyLeafCheck:false;	//是否只显示叶子节点的复选框
		var _dnd = (true==jparam.dnd)?jparam.dnd:false;									//是否启用拖放
		var _asyn = (true==jparam.asyn)?jparam.asyn:false;								//是否异步加载
		var _expandAll = (false==jparam.expandAll)?jparam.expandAll:true;				//加载完毕后是否展开所有
		
		//回调
		var _onClick = jparam.onClick?$.event_getHandler(jparam.onClick):function(){};								//当用户点击一个节点时触发
		var _onDblClick = jparam.onDblClick?$.event_getHandler(jparam.onDblClick):function(){};						//当用户双击一个节点时触发
		var _onBeforeLoad = jparam.onBeforeLoad?$.event_getHandler(jparam.onBeforeLoad):function(){};				//当加载数据的请求发出前触发
		var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(){};			//当数据加载成功时触发
		var _onLoadError = jparam.onLoadError?$.event_getHandler(jparam.onLoadError):function(){};					//当数据加载失败时触发
		var _onBeforeExpand = jparam.onBeforeExpand?$.event_getHandler(jparam.onBeforeExpand):function(){};			//节点展开前触发，返回 false 就取消展开动作
		var _onExpand = jparam.onExpand?$.event_getHandler(jparam.onExpand):function(){};							//当节点展开时触发
		var _onBeforeCollapse = jparam.onBeforeCollapse?$.event_getHandler(jparam.onBeforeCollapse):function(){};	//节点折叠前触发
		var _onCollapse = jparam.onCollapse?$.event_getHandler(jparam.onCollapse):function(){};						//当节点折叠时触发
		var _onCheck = jparam.onCheck?$.event_getHandler(jparam.onCheck):function(){};								//当用户点击 checkbox 时触发
		var _onBeforeSelect = jparam.onBeforeSelect?$.event_getHandler(jparam.onBeforeSelect):function(){};			//节点被选中前触发，返回 false 就取消选择动作。
		var _onSelect = jparam.onSelect?$.event_getHandler(jparam.onSelect):function(){};							//当节点被选中时触发
		var _onContextMenu = jparam.onContextMenu?$.event_getHandler(jparam.onContextMen):function(){};			//当右键点击节点时触发
		var _onDrop = jparam.onDrop?$.event_getHandler(jparam.onDrop):function(){};									//当节点被拖拽施放时触发
		var _onBeforeEdit = jparam.onBeforeEdit?$.event_getHandler(jparam.onBeforeEdit):function(){};				//编辑节点前触发。
		var _onAfterEdit = jparam.onAfterEdit?$.event_getHandler(jparam.onAfterEdit):function(){};					//编辑节点后触发
		var _onCancelEdit = jparam.onCancelEdit?$.event_getHandler(jparam.onCancelEdit):function(){};				//当取消编辑动作时触发
		
		$.cuajax({
			url:_url,
			data:_data,
			method:"post", 
			timeout:WDK_Timeout,
			success:function(result) {
				var jparam = eval('('+result+')');
				initAccording(jparam);
				
			},
			error:function(result){
//				alert('网络错误！result='+result);
				$.getRoot().$.messager.alert('信息提示','网络错误：'+result,'error');
			}
		});
		
		function initAccording(jparam){
			//1、构建基本html代码
			var accord_arr = [];
			for(var i=0;i<jparam.length;i++){
				var jtopmenu = jparam[i];
				accord_arr.push('<div title="'+jtopmenu.text+'" id="'+jtopmenu.id+'" style="padding: 5px;" ');
				accord_arr.push('data-options="border:false,isonCls:\'anchor\',tools : [ ');
//				accord_arr.push('{iconCls :\'database_refresh\',handler : function() {$(\'#menu_tree_'+jtopmenu.id+'\').tree(\'reload\');}	},');
				accord_arr.push('{iconCls :\'resultset_next\',handler : function() {var node = $(\'#menu_tree_'+jtopmenu.id+'\').tree(\'getSelected\');if (node) {$(\'#menu_tree_'+jtopmenu.id+'\').tree(\'expandAll\', node.target);} else {$(\'#menu_tree_'+jtopmenu.id+'\').tree(\'expandAll\');}}},');
				accord_arr.push('{iconCls :\'resultset_previous\',handler : function() {var node = $(\'#menu_tree_'+jtopmenu.id+'\').tree(\'getSelected\');if (node) {$(\'#menu_tree_'+jtopmenu.id+'\').tree(\'collapseAll\', node.target);} else {$(\'#menu_tree_'+jtopmenu.id+'\').tree(\'collapseAll\');}}}');
				accord_arr.push(']">');
				accord_arr.push('	<div id="menu_tree_'+jtopmenu.id+'" style="padding:5px;">111</div>');
				accord_arr.push('</div>');
			}
			$('#'+_id).html(accord_arr.join(''));
			
			
			//初始化树
			for(var i=0;i<jparam.length;i++){
				var jtopmenu = jparam[i];
				var _treeid = 'menu_tree_'+jtopmenu.id;
				$('#'+_treeid).tree({
					data:jtopmenu.children,
					checkbox:_checkbox,
					onLoadSuccess: function (node, data) {
						if(_expandAll){
							$('#'+_treeid).tree("expandAll");
						}else{
							$('#'+_treeid).tree("collapseAll");
						}
		            },
					onClick:_onClick,
					onDblClick:_onDblClick,
					onBeforeLoad:_onBeforeLoad,
					onLoadError:_onLoadError,
					onExpand:_onExpand,
					onBeforeCollapse:_onBeforeCollapse,
					onCollapse:_onCollapse,
					onBeforeSelect:_onBeforeSelect,
					onSelect:_onSelect,
					onContextMenu:_onContextMenu,
					onDrop:_onDrop,
					onBeforeEdit:_onBeforeEdit,
					onAfterEdit:_onAfterEdit,
					onCancelEdit:_onCancelEdit
				});
			}
			
			//2、初始化accordion
			$('#'+_id).accordion({
				border:true,
				isonCls:'anchor',
				fit:true
			 });
				
			$('#'+_id).accordion('getSelected').panel('collapse');
		}
		
		
		
//		   
//		$('#'+_id).tree({
//			url:_url,
//			data:_data,
//			checkbox:_checkbox,
//			onLoadSuccess: function (node, data) {
//				if(_expandAll){
//					$('#'+_id).tree("expandAll");
//				}else{
//					$('#'+_id).tree("collapseAll");
//				}
//            },
//            onBeforeExpand:function(node) {
//            	if(_asyn){
//            		var _asynurl = _url + '&nodeid='+node.id;
//            		$('#'+_id).tree("options").url = _asynurl;
//            	}
//            },
//			onClick:_onClick,
//			onDblClick:_onDblClick,
//			onBeforeLoad:_onBeforeLoad,
//			onLoadError:_onLoadError,
//			onExpand:_onExpand,
//			onBeforeCollapse:_onBeforeCollapse,
//			onCollapse:_onCollapse,
//			onBeforeSelect:_onBeforeSelect,
//			onSelect:_onSelect,
//			onContextMenu:_onContextMenu,
//			onDrop:_onDrop,
//			onBeforeEdit:_onBeforeEdit,
//			onAfterEdit:_onAfterEdit,
//			onCancelEdit:_onCancelEdit
//		});
	},
	/*********************************************8
	 * 				树形条控件
	 * 
	 * 	功能说明：
	 * 
	 * 	参数说明：
	 *********************************************/
	//树控件
	tree:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _url = jparam.url?jparam.url:'';											//树数据获取地址
		var _queryParams = jparam.queryParams?jparam.queryParams:{};						//url请求附带参数
		var _data = jparam.data?jparam.data:[];
		var _method = jparam.method?jparam.method:'post';								//http请求方式
		var _animate = (true==jparam.animate)?jparam.animate:false;						//是否显示折叠动画效果
		var _checkbox = (true==jparam.checkbox)?jparam.checkbox:false;					//是否显示复选框
		var _cascadeCheck = (false==jparam.cascadeCheck)?jparam.cascadeCheck:true;		//是否级联检查checkbox
		var _onlyLeafCheck = (true==jparam.onlyLeafCheck)?jparam.onlyLeafCheck:false;	//是否只显示叶子节点的复选框
		var _dnd = (true==jparam.dnd)?jparam.dnd:false;									//是否启用拖放
		var _asyn = (true==jparam.asyn)?jparam.asyn:false;								//是否异步加载
		var _expandall = (true==jparam.expandall)?jparam.expandall:false;				//加载完毕后是否展开所有
		if(_asyn){
			//如果采用异步方式，该属性必须为false
			_expandall = false;
		}
		//回调
		var _onClick = jparam.onClick?$.event_getHandler(jparam.onClick):function(){};								//当用户点击一个节点时触发
		var _onDblClick = jparam.onDblClick?$.event_getHandler(jparam.onDblClick):function(){};						//当用户双击一个节点时触发
		var _onBeforeLoad = jparam.onBeforeLoad?$.event_getHandler(jparam.onBeforeLoad):function(node,param){};				//当加载数据的请求发出前触发
		var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(){};			//当数据加载成功时触发
		var _onLoadError = jparam.onLoadError?$.event_getHandler(jparam.onLoadError):function(arguments){};					//当数据加载失败时触发
		var _onBeforeExpand = jparam.onBeforeExpand?$.event_getHandler(jparam.onBeforeExpand):function(){};			//节点展开前触发，返回 false 就取消展开动作
		var _onExpand = jparam.onExpand?$.event_getHandler(jparam.onExpand):function(){};							//当节点展开时触发
		var _onBeforeCollapse = jparam.onBeforeCollapse?$.event_getHandler(jparam.onBeforeCollapse):function(){};	//节点折叠前触发
		var _onCollapse = jparam.onCollapse?$.event_getHandler(jparam.onCollapse):function(){};						//当节点折叠时触发
		var _onCheck = jparam.onCheck?$.event_getHandler(jparam.onCheck):function(){};								//当用户点击 checkbox 时触发
		var _onBeforeCheck = jparam.onBeforeCheck?$.event_getHandler(jparam.onBeforeCheck):function(){};
		var _onBeforeSelect = jparam.onBeforeSelect?$.event_getHandler(jparam.onBeforeSelect):function(){};			//节点被选中前触发，返回 false 就取消选择动作。
		var _onSelect = jparam.onSelect?$.event_getHandler(jparam.onSelect):function(){};							//当节点被选中时触发
		var _onContextMenu = jparam.onContextMenu?$.event_getHandler(jparam.onContextMenu):function(){};			//当右键点击节点时触发
		var _onDrop = jparam.onDrop?$.event_getHandler(jparam.onDrop):function(){};									//当节点被拖拽施放时触发
		var _onBeforeEdit = jparam.onBeforeEdit?$.event_getHandler(jparam.onBeforeEdit):function(){};				//编辑节点前触发。
		var _onAfterEdit = jparam.onAfterEdit?$.event_getHandler(jparam.onAfterEdit):function(){};					//编辑节点后触发
		var _onCancelEdit = jparam.onCancelEdit?$.event_getHandler(jparam.onCancelEdit):function(){};				//当取消编辑动作时触发
			
	//	var urlparam = [];
	//	for(var att in _queryParams){
	//		urlparam.push(att+'='+_queryParams[att]);
	//	}
	//	if(urlparam.length>0&&-1==_url.indexOf("?")){
	//		_url += "?"+urlparam.join('&');
	//	}else{
	//		_url += "&"+urlparam.join('&');
	//	}
		$('#'+_id).tree({
			url:_url,
			data:_data,
			checkbox:_checkbox,
			animate:_animate,
			cascadeCheck:_cascadeCheck,
			onlyLeafCheck:_onlyLeafCheck,
			queryParams:_queryParams,
			onBeforeLoad:function(node,param){
				$.wait_open();
	        	for(var att in _queryParams){
	        		param[att] = _queryParams[att];
	        	}
	        	var res = _onBeforeLoad(node,param);
	        	if(false!=res){
	        		res = true;
	        	}
	        	return res;
	        },
	        onLoadError:function(arguments){
	        	$.wait_close();
	        	_onLoadError(arguments);
	        },
			onLoadSuccess: function (node, data) {
	        	$.wait_close();
	        	//仅对静态树有效果
	        	if(!_asyn){
					if(_expandall){
						$('#'+_id).tree("expandAll");
					}else{
						$('#'+_id).tree("collapseAll");
					}
	        	}
				_onLoadSuccess(node,data);
            },
            onBeforeExpand:function(node) {
            	if(_asyn){
            		var _asynurl = _url + '&parentid='+node.id;
            		$('#'+_id).tree("options").url = _asynurl;
            	}
            	var res = _onBeforeExpand(node);
	        	if(false!=res){
	        		res = true;
	        	}
            },
			onClick:function(node){
            	_onClick(node);
            },
			onDblClick:function(node){
            	_onDblClick(node);
            },
			onLoadError:function(XMLHttpRequest, textStatus, errorThrown){
            	_onLoadError(XMLHttpRequest, textStatus, errorThrown);
            },
			onExpand:function(node){
            	_onExpand(node);
            },
			onBeforeCollapse:function(node){
            	var res = _onBeforeCollapse(node);
            	if(false!=res){
            		res = true;
            	}
            	return res;
            },
			onCollapse:function(node){
            	_onCollapse(node);
            },
            onCheck:function(node, checked){
            	_onCheck(node, checked);
            },
            onBeforeCheck:function(node,checked){
            	var res = _onBeforeCheck(node,checked);
            	return res;
            },
			onBeforeSelect:function(node){
            	var res = _onBeforeSelect(node);
            	if(false!=res){
            		res = true;
            	}
            	return res;
            },
			onSelect:function(node){
            	_onSelect(node);
            },
			onContextMenu:_onContextMenu,
			onDrop:_onDrop,
			onBeforeEdit:_onBeforeEdit,
			onAfterEdit:_onAfterEdit,
			onCancelEdit:_onCancelEdit
		});
		return _id;
	},
	//结果集转换，适应树的格式
	tree_translateData:function(jrows){
		var arr = [];
		
		for(var i=0;i<jrows.length;i++){
			var jrow = jrows[i];
			if(jrow.parentid){
				continue;
			}
			var jnode = new Object();
			jnode.id = jrow.id;
			jnode.text = jrow.name;
			jnode.attributes = new Object();
			jnode.attributes.type = jrow.type;
			jnode.attributes.icon = jrow.icon;
			jnode.attributes.onclick = jrow.onclick;
			jnode.attributes.parentid = jrow.parentid;
			jnode.attributes.html = jrow.html;
			
			$.tree_translateData_iterator(jrows,jnode);
			
			arr.push(jnode);
		}
		return arr;
	},
	tree_translateData_iterator:function(jrows,jparent){
		for(var i=0;i<jrows.length;i++){
			var jrow = jrows[i];
			if(jrow.parentid==jparent.id){
				if(!jparent.children){
					jparent.children = [];
				}
				var jnode = new Object();
				jnode.id = jrow.id;
				jnode.text = jrow.name;
				jnode.attributes = new Object();
				jnode.attributes.type = jrow.type;
				jnode.attributes.icon = jrow.icon;
				jnode.attributes.onclick = jrow.onclick;
				jnode.attributes.parentid = jrow.parentid;
				jnode.attributes.html = jrow.html;
				$.tree_translateData_iterator(jrows,jnode);
				jparent.children.push(jnode);
			}
		}
	},
	//获取树的所有节点
	tree_getAllNode:function(jparam){
		var _id = jparam.id;
		var roots = $('#'+_id).tree('getRoots');
		var arr = [];
		for(var i=0;i<roots.length;i++){
			var children = $('#'+_id).tree('getChildren',roots[i].target);
		     for(j=0;j<children.length;j++){
		    	 arr.push(children[j]);
		     }
		}
		return arr;
	},
	//根据父节点获取所有子节点
	tree_getChildNodes:function(jparam){
		var _id = jparam.id;
		var _node = jparam.node;
		var childNodes = $('#'+_id).tree('getChildren',_node.target);
		return childNodes;
		
	},
	//获取选中的值，以,分割
	tree_getChecked:function(jparam){
		var _id = jparam.id;
		var nodes = $('#'+_id).tree('getChecked');
		if(nodes.length<1){
			nodes = [$('#'+_id).tree('getSelected')];
		}
		if(null==nodes||''==nodes){
			return null;
		}
        var _idarr = [];
        var _textarr = [];
        for (var i = 0; i < nodes.length; i++) {
        	_idarr.push(nodes[i].id);
        	_textarr.push(nodes[i].text);
        }
    	return {id:_idarr.join(','),text:_textarr.join(',')};  
	},
	//获取所有选中的节点对象
	tree_getCheckedNode:function(jparam){
		var _id = jparam.id;
		var nodes = $('#'+_id).tree('getChecked');
		if(nodes.length<1){
			nodes = [$('#'+_id).tree('getSelected')];
		}
        var _arr = [];
        for (var i = 0; i < nodes.length; i++) {
        	if(nodes[i]){
        		_arr.push(nodes[i]);
        	}
        }
    	return _arr;  
	},
	//设置选中
	tree_setChecked:function(jparam){
		var _id = jparam.id;
		var _ischeckbox = $("#"+_id).tree('options').checkbox;
		var _ids = jparam.ids?jparam.ids:'';
		var idarr = _ids.split(',');
		for(var i=0;i<idarr.length;i++){
			var nodeid = idarr[i];
			var node = $("#"+_id).tree('find',nodeid);
			if(node){
				if(_ischeckbox){
					$("#"+_id).tree('check',node.target);
				}else{
					$("#"+_id).tree('select',node.target);
				}
			}
		}
	},
	tree_setCheckedAll:function(jparam){
		var _id = jparam.id;
		var allnodes = $.tree_getAllNode({id:_id});
		var _ischeckbox = $("#"+_id).tree('options').checkbox;
		for(var i=0;i<allnodes.length;i++){
			var node = allnodes[i];
			if(node){
				if(_ischeckbox){
					$("#"+_id).tree('check',node.target);
				}else{
					$("#"+_id).tree('select',node.target);
				}
			}
		}
	},
	//设置选中
	tree_unChecked:function(jparam){
		var _id = jparam.id;
		var _ischeckbox = $("#"+_id).tree('options').checkbox;
		var _ids = jparam.ids?jparam.ids:'';
		var idarr = _ids.split(',');
		for(var i=0;i<idarr.length;i++){
			var nodeid = idarr[i];
			var node = $("#"+_id).tree('find',nodeid);
			if(node){
				if(_ischeckbox){
					$("#"+_id).tree('uncheck',node.target);
				}else{
					//$("#"+_id).tree('unselect',node.target);
				}
			}
		}
	},
	tree_unCheckedAll:function(jparam){
		var _id = jparam.id;
		var allnodes = $.tree_getAllNode({id:_id});
		var _ischeckbox = $("#"+_id).tree('options').checkbox;
		for(var i=0;i<allnodes.length;i++){
			var node = allnodes[i];
			if(node){
				if(_ischeckbox){
					$("#"+_id).tree('uncheck',node.target);
				}else{
					//$("#"+_id).tree('unselect',node.target);
				}
			}
		}
	},
	//重新加载
	tree_reload:function(jparam){
		var _id = jparam.id;
		var _opts = $('#'+_id).tree('options');
		
		var _data = jparam.data?jparam.data:null;
		var _url = jparam.url?jparam.url:_opts.url;
		var _newQueryParams = jparam.queryParams?jparam.queryParams:{};
		
		var _oldQueryParams = _opts.queryParams;
		for(var att in _newQueryParams){
			_oldQueryParams[att] = _newQueryParams[att];
		}
		if(_data){
			$('#'+_id).tree('options').data = _data;
		}
		if(_url){
			$('#'+_id).tree('options').url = _url;
		}
			
		$('#'+_id).tree('options').queryParams = _oldQueryParams;
		$('#'+_id).tree('reload');
	},
	
	//设置选中
	tree_remove:function(jparam){
		var _id = jparam.id;
		var _ids = jparam.ids?jparam.ids:'';
		var idarr = _ids.split(',');
		for(var i=0;i<idarr.length;i++){
			var nodeid = idarr[i];
			var node = $("#"+_id).tree('find',nodeid);
			if(node){
				$("#"+_id).tree('remove',node.target);
			}
		}
	},
	/*********************************************8
	 * 				树形表格控件
	 * 
	 * 	功能说明：
	 * 
	 * 	参数说明：
	 *********************************************/
	//树形表格
	treegrid:function(jparam){
		var _id = jparam.id?jparam.id:$.getUUID();
		var _gridcode = jparam.gridcode?jparam.gridcode:'';									//grid编码，在数据库中关联表头和格式
		var _idField = jparam.idField?jparam.idField:'id';									//主键字段
		var _textField = jparam.textField?jparam.textField:'text';							//树节点text显示字段
		var _valueField = jparam.valueField?jparam.valueField:'value';						//树节点text显示字段
		
		var _url = jparam.url?jparam.url:'';												//grid数据获取url
		var _fit = (false==jparam.fit)?jparam.fit:true;										//自动大小
		var _asyn = (true==jparam.asyn)?jparam.asyn:false;									//是否异步加载，默认同步
		var _width = jparam.width?jparam.width:'auto';										//宽度
		var _height = jparam.height?jparam.height:'auto';									//高度
		var _animate = (true==jparam.animate)?jparam.animate:false;							//是否显示动画效果
		var _expandAll = (false==jparam.expandAll)?jparam.expandAll:true;				//加载完毕后是否展开所有
		var _collapsible = (true==jparam.collapsible)?jparam.collapsible:false;				//是否可折叠的  
		var _nowrap = (false==jparam.nowrap)?jparam.nowrap:true;							//是否不折行
		var _striped = (false==jparam.striped)?jparam.striped:true;							//奇偶行不同颜色
		var _border = (true==jparam.border)?jparam.border:false;							//是否显示边框
		var _initdata = jparam.initdata?jparam.initdata:{};									//新增默认数据
		var _queryParams = jparam.queryParams?jparam.queryParams:{};						//url请求附带参数
		var _singleSelect = (false==jparam.singleSelect)?jparam.singleSelect:true;			//是否单选  
		var _rownumbers = (false==jparam.rownumbers)?jparam.rownumbers:true;				//是否显示行号
//		var _checkbox = (true==jparam.checkbox)?jparam.checkbox:false;						//是否显示checkbox
//		var _checkOnSelect = (false==jparam.checkOnSelect)?jparam.checkOnSelect:true;		//选中该行是否联动勾选checkbox
//		var _selectOnCheck = (false==jparam.selectOnCheck)?jparam.selectOnCheck:true;		//勾选check是否联动选中改行
		
		var _showContextMenu = (false==jparam.showContextMenu)?jparam.showContextMenu:true;	//是否显示右键菜单
		
		
		//各类事件
		var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(row, data){};			//当数据加载成功时触发。
		var _onLoadError = jparam.onLoadError?$.event_getHandler(jparam.onLoadError):function(arguments){};				//当数据加载失败时触发， arguments 参数和 jQuery.ajax 的 'error' 方法一样。
		var _onBeforeLoad = jparam.onBeforeLoad?$.event_getHandler(jparam.onBeforeLoad):function(row, param){};				//发出一个加载数据的请求前触发，返回 false 就取消加载动作。
		var _onClickRow = jparam.onClickRow?$.event_getHandler(jparam.onClickRow):function(row){};							//当用户点击一个节点时触发。
		var _onDblClickRow = jparam.onDblClickRow?$.event_getHandler(jparam.onDblClickRow):function(row){return true;};		//当用户双击一个节点时触发。
		
		var _onBeforeExpand = jparam.onBeforeExpand?$.event_getHandler(jparam.onBeforeExpand):function(row){};			//节点展开前触发，返回 false 就取消展开动作。
		var _onExpand = jparam.onExpand?$.event_getHandler(jparam.onExpand):function(row){};							//当节点展开时触发
		var _onBeforeCollapse = jparam.onBeforeCollapse?$.event_getHandler(jparam.onBeforeCollapse):function(row){};	//节点折叠前触发，返回 false 就取消折叠动作。。
		var _onCollapse = jparam.onCollapse?$.event_getHandler(jparam.onCollapse):function(row){};						//当节点折叠时触发。
		var _onContextMenu = jparam.onContextMenu?$.event_getHandler(jparam.onContextMenu):function(e, row){};			//当右键点击节点时触发
		var _onBeforeEdit = jparam.onBeforeEdit?$.event_getHandler(jparam.onBeforeEdit):function(row){};				//当用户开始编辑节点时触发。
		var _onAfterEdit = jparam.onAfterEdit?$.event_getHandler(jparam.onAfterEdit):function(row,changes){};					//当用户完成编辑时触发。
		var _onCancelEdit = jparam.onCancelEdit?$.event_getHandler(jparam.onCancelEdit):function(row){};				//当用户取消编辑节点时触发。
	

		
		
		if(-1==_url.indexOf('?')){
			_url += '?asyn='+_asyn;
		}else{
			_url += '&asyn='+_asyn;
		}
		
		//1、从后台读取grid配置以及个人默认样式，然后附加datagrid属性
		//var _data = [{name:"gridcode",value:_gridcode}];
		var _data = {gridcode:_gridcode};
		$.cuajax({
		  	url:'wdk?action=wdk.public&method=treegrid_loadHead&ajaxparam='+new Date().getTime(),
			method:"post", 
			timeout:WDK_Timeout,
			data:_data,   
			success:function(result) {
				var jparam = eval('('+result+')');
				try{
					//1、生成表头数据
					var jcols = [];
					for(var i=0;i<jparam.fields.length;i++){
						var jfield = jparam.fields[i];
						var jcol = new Object();
						jcol.field = jfield.fieldcode;
						jcol.title = jfield.fieldname;
						jcol.width = jfield.width;
						jcol.align = jfield.align;
						if("1"==jfield.ishidden||"是"==jfield.ishidden){
							jcol.hidden = true;
						}
						jcols.push(jcol);
					}
					var jcolumns = [];
					jcolumns.push(jcols);
					
					
					//2、注册treegrid
					 $('#'+_id).treegrid({
						 url:_url, 
						 queryParams:_queryParams,
						 idField:_idField,
						 treeField:_textField,  
						 fit:_fit,
						 asyn:_asyn,
						 singleSelect:_singleSelect,
						 nowrap:_nowrap,
						 striped:_striped,
						 border:_border,
//						 checkbox:_checkbox,
//						 checkOnSelect:_checkOnSelect,
//						 selectOnCheck:_selectOnCheck,
						 rownumbers: _rownumbers,  
						 animate:_animate,  
						 columns:jcolumns,
//						 frozenColumns:[[
//						                 {field:'ck',checkbox:true}
//						             ]],
						 onBeforeExpand:function(row){
						 	if(_asyn&&row){
						 		var arr = [];
						 		for(var att in row){
						 			arr.push(att+'='+encodeURI(encodeURI(row[att])));
						 		}
						 		var url = _url+'&parentid='+encodeURI(encodeURI(row.id));
						 		if(arr.length>0){
						 			url += "&"+arr.join('&');
						 		}
						 		$(this).treegrid('options').url= url;
						 	}
					 	}
					 	,onLoadSuccess:function(row, data){
					 		if(_asyn){
					 			
					 		}else{
						 		if(_expandAll){
									$('#'+_id).treegrid("expandAll");
								}else{
									$('#'+_id).treegrid("collapseAll");
								}
					 		}
					 		_onLoadSuccess(row, data);
					 	}
					 	//加载右键菜单
					 	,onContextMenu:function(e, rowData){//右键时触发事件
				             //三个参数：e里面的内容很多，真心不明白，rowIndex就是当前点击时所在行的索引，rowData当前行的数据
				        	if(!_showContextMenu){
				        		return false; 
				        	}
				        	e.preventDefault(); //阻止浏览器捕获右键事件
//				             $(this).datagrid("clearSelections"); //取消所有选中项
//				             $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
				             
				        	//var rows = $.treegrid_getSelections({id:_id});
				        	
				        	
				             if(!$('#'+_ID_grid_contextmenu).html()){
				            	//如果右键菜单还没有构建，则实时构建
				            	 var arr = [];
					             arr.push('<div onclick="_treegrid_export(\''+_gridcode+'\',\''+_id+'\',\''+_idField+'\',\'1\')">导出所有</div>');
					             arr.push('<div onclick="_treegrid_export(\''+_gridcode+'\',\''+_id+'\',\''+_idField+'\',\'2\')">导出所有根节点</div>');
					             arr.push('<div onclick="_treegrid_export(\''+_gridcode+'\',\''+_id+'\',\''+_idField+'\',\'3\')">导出选中</div>');
				            	 $('#'+_ID_grid_contextmenu).html(arr.join(''));
				            	 $('#'+_ID_grid_contextmenu).menu();
				             }
				             $('#'+_ID_grid_contextmenu).menu('show', {		//显示右键菜单
				                 left: e.pageX,//在鼠标点击处显示菜单
				                 top: e.pageY
				             	});
				         }
					 	,onLoadError:function(XMLHttpRequest, textStatus, errorThrown){
					 		_onLoadError(XMLHttpRequest, textStatus, errorThrown);
					 	}
					 	,onClickRow:function(row){
					 		_onClickRow(row);
					 	}
					 	,onDblClickRow:function(row){
					 		_onDblClickRow(row);
					 	}
					 	,onBeforeLoad:function(row, param){
					 		_onBeforeLoad(row, param);
					 	}
					 	
					 	,onExpand:function(row){
					 		_onExpand(row);
					 	}
					 	,onBeforeCollapse:function(row){
					 		_onBeforeCollapse(row);
					 	}
					 	,onCollapse:function(row){
					 		_onCollapse(row);
					 	}
					 	,onBeforeEdit:function(row){
					 		_onBeforeEdit(row);
					 	}
					 	,onAfterEdit:function(row,changes){
					 		_onAfterEdit(row,changes);
					 	}
					 	,onCancelEdit:function(){
					 		_onCancelEdit(row);
					 	}
					 	
				
					 });  
				}catch(e){
//					alert(e.message);
					$.getRoot().$.messager.alert('信息提示','treegrid加载错误','error');
				}
			},
			error:function(result){
//				alert('网络错误！result='+result);
				$.getRoot().$.messager.alert('信息提示','网络错误：'+result,'error');
			}
		});
		return _id;
	},
	
	treegrid_export_excel:function(jparam){
		var _gridcode = jparam.gridcode;
		var _id = jparam.id;
		var _epclass = 'treegrid';									//控件类型
		var _epformat = jparam.epformat?jparam.epformat:'excel';	//导出格式	
		var _eptype = jparam.eptype?jparam.eptype:'1';				//导出方式：1-导出所有	2-导出所有根节点	3-导出选中
		var _rowid = jparam.rowid?jparam.rowid:'';
		
		var _options =  $('#'+_id).treegrid('options');
		var _url = _options.url;
		var _queryParams = _options.queryParams;
		var _treeField = _options.treeField;
		
		var _data = [
		             {name:'h_action_type',value:'export'},			//用于baseaction中对请求进行判断
		             {name:'epclass',value:_epclass},
		             {name:'epformat',value:_epformat},
		             {name:'eptype',value:_eptype},
		             {name:'gridcode',value:_gridcode},
		             {name:'rowid',value:_rowid},
		             {name:'treeField',value:_treeField}
			     	];
		for(var att in _queryParams){
			_data.push({name:att,value:_queryParams[att]});
		}
		var _urlparamarr = [];
		for(var i=0;i<_data.length;i++){
			var pa = _data[i];
			_urlparamarr.push(pa.name+"="+pa.value);
		}
		_url += "&"+_urlparamarr.join('&');
		_url = $.base()+"/"+_url;
		$.download({url:_url});
	},
	treegrid_reload:function(jparam){
		var _id = jparam.id;
		var _newQueryParams = jparam.queryParams?jparam.queryParams:{};
		var _oldQueryParams = $('#'+_id).treegrid('options').queryParams;
		for(var att in _newQueryParams){
			_oldQueryParams[att] = _newQueryParams[att];
		}
		$('#'+_id).treegrid({queryParams:_oldQueryParams});
	    //取消所有选中的行
	    $('#'+_id).treegrid('unselectAll');  
	},
	treegrid_getColums:function(jparam){
		var cols = [];
		var _id = jparam.id;
		var options = $('#'+_id).treegrid('options');
		for(var i=0;i<options.columns.length;i++){
			for(var j=0;j<options.columns[i].length;j++){
				var col = options.columns[i][j];
				cols.push(col.field);
			}
		}
		return cols;
	},
	//获取所有的选中行，返回选中行数组
	treegrid_getSelections:function(jparam){
		var _id = jparam.id;
		var rows = $("#"+_id).treegrid("getSelections");
		rows = $.treegrid_formatDatas({id:_id,data:rows});
		return rows;
	},
	treegrid_formatDatas:function (jparam){
		var _id = jparam.id;
		var _rows = jparam.data;
		var _cols = $.treegrid_getColums({id:_id});
		var tmpRows = [];
		for(var i=0;i<_rows.length;i++){
			var _row = _rows[i];
			var tmpRow = new Object();
			for(var j=0;j<_cols.length;j++){
				var att = _cols[j];
				var str = _row[att];
				tmpRow[att] = $.grid_getCellData(str);
			}
			tmpRows.push(tmpRow);
		}
		return tmpRows;
	},
	//设置选中
	treegrid_setSelect:function(jparam){
		var _id = jparam.id;
		var _ids = jparam.ids?jparam.ids:'';
		var idarr = _ids.split(',');
		for(var i=0;i<idarr.length;i++){
			var nodeid = idarr[i];
			var node = $("#"+_id).treegrid('find',nodeid);
			if(node){
				$("#"+_id).treegrid('select',nodeid);
			}
		}
		
	},
	/*********************************************8
	 * 				页签控件
	 * 
	 * 	功能说明：
	 * 
	 * 	参数说明：
	 *********************************************/
	//定义页签
	tab:function(jparam){
		var _containerid = jparam.containerid;
		var _id = $.getID();
		jparam.tabid = _id;
		
//		var _onLoad = jparam.onLoad?jparam.onLoad:function(panel){};						//当一个 ajax tab panel 完成加载远程数据时触发。
//		var _onSelect = jparam.onSelect?jparam.onSelect:function(title){};					//当用户选择一个 tab panel 时触发。
//		var _onBeforeClose = jparam.onBeforeClose?jparam.onBeforeClose:function(title){};	//当一个 tab panel 被关闭前触发，返回 false 就取消关闭动作。
//		var _onClose = jparam.onClose?jparam.onClose:function(title){};						//当用户关闭一个 tab panel 时触发。
//		var _onAdd = jparam.onAdd?jparam.onAdd:function(title){};							//当一个新的 tab panel 被添加时触发。
//		var _onUpdate = jparam.onUpdate?jparam.onUpdate:function(title){};					//当一个 tab panel 被更新时触发。
		
		var _onLoad = jparam.onLoad?$.event_getHandler(jparam.onLoad):function(){};
		var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(){};
		var _onSelect = jparam.onSelect?$.event_getHandler(jparam.onSelect):function(){};
		var _onBeforeClose = jparam.onBeforeClose?$.event_getHandler(jparam.onBeforeClose):function(){};
		var _onClose = jparam.onClose?$.event_getHandler(jparam.onClose):function(){};
		var _onAdd = jparam.onAdd?$.event_getHandler(jparam.onAdd):function(){};
		var _onUpdate = jparam.onUpdate?$.event_getHandler(jparam.onUpdate):function(){};
		
		jparam.gfvid = $.method_reg(window,'_handler_getFieldValue');
		
		if(_onLoad){
			jparam.onLoad = $.method_reg(window,_onLoad);
		}
		if(_onLoadSuccess){
			jparam.onLoadSuccess = $.method_reg(window,_onLoadSuccess);
		}
		if(_onSelect){
			jparam.onSelect = $.method_reg(window,_onSelect);
		}
		if(_onBeforeClose){
			jparam.onBeforeClose = $.method_reg(window,_onBeforeClose);
		}
		if(_onClose){
			jparam.onClose = $.method_reg(window,_onClose);
		}
		if(_onAdd){
			jparam.onAdd = $.method_reg(window,_onAdd);
		}
		if(_onUpdate){
			jparam.onUpdate = $.method_reg(window,_onUpdate);
		}
		
		//加载内容
		var jsonstr = $.json2str(jparam);
		jsonstr = jsonstr.replace(/\'/ig,"\\\'").replace(/\"/ig,"\\\'");
		var _src = WDK_ROOT+'/module/public/tab.jsp';
		if(jparam.type){
			_src = WDK_ROOT+'/module/public/tab_'+jparam.type+'.jsp';
		}
		
		var strIframe = '<iframe id="'+_id+'" name="'+_id+'" src="'+_src+'"  width="100%" height="100%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" onload="this.contentWindow.init(\''+jsonstr+'\')"></iframe>';
		$('#'+_containerid).html(strIframe);
		return _id;
	},
	//获取标签页里面的iframe对象
	tab_getTab:function(jparam){
		var _id = jparam.id;
		var _title = jparam.title;
		var ifrTabFrame = document.getElementById(_id);
		var ifrTab = ifrTabFrame.contentWindow.document.getElementById(_title);
		return ifrTab;
	},
	//获取顶层页签的iframe对象
	tab_getTabTop:function(jparam){
		if(!jparam){
			jparam = new Object();
		}
		var _top = $.getRoot();
		var _tabid = $.getURLParam('tabid');
		var _title = jparam.title;
		if(!_title){
			_title = $.getURLParam('tabtitle');
		}
		var ifrTabFrame = _top.document.getElementById(_tabid);
		var ifrTab = ifrTabFrame.contentWindow.document.getElementById(_title);
		return ifrTab;
	},
	//获取指定页签选中的页签页面的ifr对象
	tab_getSelected:function(jparam){
		var _id = jparam.id;
		var ifrTabFrame = document.getElementById(_id);
		var tab = ifrTabFrame.contentWindow.$('#tabs').tabs('getSelected');
		var _title = tab.panel('options').title;	//	alert(tab.panel('options').content);
		var ifrTab = ifrTabFrame.contentWindow.document.getElementById(_title);
	//	alert('tab_getSelected   _title='+_title+'   ifrTab='+ifrTab);
		return ifrTab;
	},
	//获取顶级框架页签选中的页签页面的ifr对象
	tab_getSelectedTop:function(){
		var _tabid = $.getURLParam('tabid');
		var _top = $.getRoot();
		var ifrTabFrame = _top.document.getElementById(_tabid);
		var tab = ifrTabFrame.contentWindow.$('#tabs').tabs('getSelected');
		var _title = tab.panel('options').title;	//	alert(tab.panel('options').content);
		var ifrTab = ifrTabFrame.contentWindow.document.getElementById(_title);
		return ifrTab;
		
	},
	//动态修改tab的title，不刷新
	tab_setTab:function(jparam){
		var _id = jparam.id;
		var _title = jparam.title;
		var _newtitle = jparam.newtitle;
		var _newurl = jparam.newurl?jparam.newurl:'';
		var _closable = (false==jparam.closable)?jparam.closable:true;
		
		var ifrTabFrame = document.getElementById(_id);
		var currTab = ifrTabFrame.contentWindow.$('#tabs').tabs('getTab',_title);
		if(currTab){
			if(_newurl){
				//如果有url，则刷新
				if(-1==_newurl.indexOf("?")){
					_newurl += "?gfvid="+ifrTabFrame.contentWindow._gfvid;
				}else{
					_newurl += "&gfvid="+ifrTabFrame.contentWindow._gfvid;
				}
				ifrTabFrame.contentWindow.$('#tabs').tabs('update',{
					tab:currTab,
					options:{
						title:_newtitle,   
						content:'<iframe id="'+_newtitle+'" name="'+_newtitle+'" src="'+_newurl+'"  width="100%" height="98%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" ></iframe>',   
						closable:_closable
					}
				});  
			}else{
				//如果没有url，就更新名字
				ifrTabFrame.contentWindow.$('#tabs').tabs('setTabTitle',{tab:currTab,title:_newtitle});
			}
		}
	},
	//动态修改tab的title，不刷新
	tab_setTabTop:function(jparam){
		var _tabid = $.getURLParam('tabid');
		var _top = $.getRoot();
		
		var _title = jparam.title;
		if(!_title){
			_title = $.getURLParam('tabtitle');
		}
		var _newtitle = jparam.newtitle;
		var _newurl = jparam.newurl?jparam.newurl:'';
		var _closable = (false==jparam.closable)?jparam.closable:true;
		
		
		
		var ifrTabFrame = _top.document.getElementById(_tabid);
		var currTab = ifrTabFrame.contentWindow.$('#tabs').tabs('getTab',_title);
		if(currTab){
			if(_newurl){
				//如果有url，则刷新
				if(-1==_newurl.indexOf("?")){
					_newurl += "?tabid="+ifrTabFrame.contentWindow._tabid+"&tabtitle="+_title+"&gfvid="+ifrTabFrame.contentWindow._gfvid;
				}else{
					_newurl += "&tabid="+ifrTabFrame.contentWindow._tabid+"&tabtitle="+_title+"&gfvid="+ifrTabFrame.contentWindow._gfvid;
				}
				ifrTabFrame.contentWindow.$('#tabs').tabs('update',{
					tab:currTab,
					options:{
						title:_newtitle,   
						content:'<iframe id="'+_newtitle+'" name="'+_newtitle+'" src="'+_newurl+'"  width="100%" height="98%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" ></iframe>',   
						closable:_closable
					}
				});  
			}else{
				//如果没有url，就更新名字
				ifrTabFrame.contentWindow.$('#tabs').tabs('setTabTitle',{tab:currTab,title:_newtitle});
			}
		}
	},
	tab_close:function(jparam){
		var _id = jparam.id;
		var _title = jparam.title;
		
		var ifrTabFrame = document.getElementById(_id);
		var currTab = ifrTabFrame.contentWindow.$('#tabs').tabs('getTab',_title);
		if(currTab){
			var tabIndex = ifrTabFrame.contentWindow.$('#tabs').tabs('getTabIndex', currTab);
			var alltabs = ifrTabFrame.contentWindow.$('#tabs').tabs('tabs');
			var afterIndex = tabIndex;
			if(alltabs.length>2){
				if(afterIndex==alltabs.length){
					afterIndex = afterIndex - 1;
				}
			}else if(alltabs.length==2){
				afterIndex = 0;
			}else{
				afterIndex = -1;
			}
			ifrTabFrame.contentWindow.$('#tabs').tabs('close',_title);
			if(afterIndex>-1){
				ifrTabFrame.contentWindow.$('#tabs').tabs('select', afterIndex);
			}
		}
	},
	tab_closeTop:function(jparam){
		var _tabid = $.getURLParam('tabid');
		var _top = $.getRoot();
		
		var _title = jparam?jparam.title:null;
		if(!_title){
			_title = $.getURLParam('tabtitle');
		}
		var ifrTabFrame = _top.document.getElementById(_tabid);
		var currTab = ifrTabFrame.contentWindow.$('#tabs').tabs('getTab',_title);
		if(currTab){
			var tabIndex = ifrTabFrame.contentWindow.$('#tabs').tabs('getTabIndex', currTab);
			var alltabs = ifrTabFrame.contentWindow.$('#tabs').tabs('tabs');
			var afterIndex = tabIndex;
			if(alltabs.length>2){
				if(afterIndex==alltabs.length){
					afterIndex = afterIndex - 1;
				}
			}else if(alltabs.length==2){
				afterIndex = 0;
			}else{
				afterIndex = -1;
			}
			ifrTabFrame.contentWindow.$('#tabs').tabs('close',_title);
			if(afterIndex>-1){
				ifrTabFrame.contentWindow.$('#tabs').tabs('select', afterIndex);
			}
		}
	},
	
	
	//更新tab的url并刷新
//	tab_updateTab:function(jparam){
//		var _id = jparam.id;
//		var _oldtitle = jparam.oldtitle;
//		var _newtitle = jparam.newtitle?jparam.newtitle:"";
//		var _newurl = jparam.newurl?jparam.newurl:'';
//		var _closable = (false==jparam.closable)?jparam.closable:true;
//		var ifrTabFrame = document.getElementById(_id);
//		var currTab = ifrTabFrame.contentWindow.$('#tabs').tabs('getTab',_oldtitle);
//		if(currTab){
//			if(-1==_newurl.indexOf("?")){
//				_newurl += "?gfvid="+ifrTabFrame.contentWindow._gfvid;
//			}else{
//				_newurl += "&gfvid="+ifrTabFrame.contentWindow._gfvid;
//			}
//			ifrTabFrame.contentWindow.$('#tabs').tabs('update',{
//				tab:currTab,
//				options:{
//					title:_newtitle,   
//					content:'<iframe id="'+_newtitle+'" name="'+_newtitle+'" src="'+_newurl+'"  width="100%" height="98%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" ></iframe>',   
//					closable:_closable
//				}
//			});  
//		}
//	},
	//页签-新增
	tab_add:function(jparam){
		var _id = jparam.id;
		var _jtab = jparam.jtab?jparam.jtab:null;
		if(-1==_jtab.url.indexOf("?")){
			_jtab.url += "?menucode="+_jtab.menucode;
		}else{
			_jtab.url += "&menucode="+_jtab.menucode;
		}
		var _param = jparam.param?jparam.param:{};
		var _ifr_tab = document.getElementById(_id);
		_ifr_tab.contentWindow.tab_add(_jtab);
	},
	//顶层框架页签添加页签页
	tab_addTop:function(jtab){
		$.getRoot().tab_add(jtab);
	},
	tab_getParentFieldValue:function(jparam){
		var _gfvid = $.getURLParam('gfvid');
		var _v = $.method_call(_gfvid,jparam);
		return _v;
	},
	//iframe标签
	iframe:function(jparam){
		var _containerid = jparam.containerid;
		var _id = jparam.id;
		var _url = jparam.url;
		var _param = jparam.param;
		var _height = jparam.height?jparam.height:'100%';
		var _width = jparam.width?jparam.width:'100%';
		
		//加载内容
		var jsonstr = new Object();
		if(_param){
			$.json2str(_param);
			jsonstr = jsonstr.replace(/\'/ig,"\\\'").replace(/\"/ig,"\\\'");
		}
		
		var strIframe = '<iframe id="'+_id+'" name="'+_id+'" src="'+_url+'"  width="'+_width+'" height="'+_height+'" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="yes" onload="javascript:if(this.contentWindow&&this.contentWindow.init){this.contentWindow.init(\''+jsonstr+'\')}"></iframe>';
		$('#'+_containerid).html(strIframe);
	},
	//验证输入框控件
	validatebox:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _initvalue = jparam.initvalue?jparam.initvalue:'';
		var _required = (true==jparam.required)?jparam.required:false;
		var _editable = (false==jparam.editable)?jparam.editable:true;
		var _missingMessage = jparam.missingMessage?jparam.missingMessage:'该项不能为空';
		var _tipPosition = jparam.tipPosition?jparam.tipPosition:'bottom';
		var _validType = jparam.validType?jparam.validType:'';
		//if(!_required){
		//	_validType = '';
		//}
		$('#'+_id).attr('isrequired',_required);
		$('#'+_id).val(_initvalue);
		$('#'+_id).validatebox({
			required:_required,
			editable:_editable,
			missingMessage:_missingMessage,
			tipPosition:_tipPosition,
			validType:_validType
		});
		$('#'+_id).validatebox('validate');
		
	},
	validatebox_getValue:function(jparam){
		var _id = jparam.id;
		var _value = $('#'+_id).val();
		return _value;
	},
	validatebox_setValue:function(jparam){
		var _id = jparam.id;
		var _value = jparam.value;
		$('#'+_id).val(_value);
		$('#'+_id).validatebox('validate');
	},
	validatebox_clear:function(jparam){
		var _id = jparam.id;
		$.validatebox_setValue({id:_id,value:''});
	},
	validatebox_disabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).attr("disabled","disabled");
	},
	validatebox_enabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).removeAttr("disabled");
	},
	text_disabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).attr("disabled","disabled");
	},
	text_enabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).removeAttr("disabled");
	},
	//下拉框
	combobox:function(jparam){
		var _id = jparam.id?jparam.id:null;
		if(!_id){
//			alert('未填写combobox的id');
			$.getRoot().$.messager.alert('信息提示','combobox的id未定义','error');
			return;
		}
		var _url = jparam.url?jparam.url:'';
		var _queryParams = jparam.queryParams?jparam.queryParams:{};
		
		var _initvalue = jparam.initvalue?jparam.initvalue:null;
//		var _disabled = (true==jparam.disabled)?jparam.disabled:false;
		var _idField = jparam.idField?jparam.idField:'id';
		var _textField = jparam.textField?jparam.textField:'text';
		var _data = jparam.data?jparam.data:[];
		var _defaultOption = jparam.defaultOption?jparam.defaultOption:null;
		var _isDefaultOption = false;
		
		var _isinitselect = (true==jparam.isinitselect)?jparam.isinitselect:false;	//是否默认就选中第一条
		var _width = jparam.width?jparam.width:'auto';		
		var _panelWidth = jparam.panelWidth?jparam.panelWidth:'';					//弹出列表高度
		var _panelHeight = jparam.panelHeight?jparam.panelHeight:200;				//弹出列表高度
		var _multiple = (true==jparam.multiple)?jparam.multiple:false;				//是否支持多选
		var _separator = jparam.separator?jparam.separator:',';						//多选的返回分隔符
//		var _value = jparam.value?jparam.value:'';						
//		var _delay = jparam.delay?jparam.delay:200;

		var _required = (true==jparam.required)?jparam.required:false;						//是否必须
		var _editable = (true==jparam.editable)?jparam.editable:false;						//是否允许手工编辑,允许编辑状态下会自动过滤选项
		var _missingMessage = jparam.missingMessage?jparam.missingMessage:'该项不能为空';	
		var _tipPosition = jparam.tipPosition?jparam.tipPosition:'bottom';					
		
//		var _filter = jparam.filter?jparam.filter:function(q,row){};				//过滤条件
//		var _formatter = jparam.formatter?jparam.formatter:function(row){};			//格式化函数
		
		
		var _onShowPanel = jparam.onShowPanel?$.event_getHandler(jparam.onShowPanel):function(){};
		var _onHidePanel = jparam.onHidePanel?$.event_getHandler(jparam.onHidePanel):function(){};
		var _onChange = jparam.onChange?$.event_getHandler(jparam.onChange):function(newValue, oldValue){};
		
		var _onLoadSuccess = jparam.onLoadSuccess?$.event_getHandler(jparam.onLoadSuccess):function(data){};		//当远程数据加载成功时触发
		var _onLoadError = jparam.onLoadError?$.event_getHandler(jparam.onLoadError):function(){};				//当远程数据加载失败时触发
		var _onSelect = jparam.onSelect?$.event_getHandler(jparam.onSelect):function(record){};					//当用户选择一个列表项时触发
		var _onUnselect = jparam.onUnselect?$.event_getHandler(jparam.onUnselect):function(record){};			//当用户取消选择一个列表项时触发
		
		$('#'+_id).attr('isrequired',_required);
		var _combobox;
		if(_url){
			var arr = [];
			for(var att in _queryParams){
				arr.push(att+'='+_queryParams[att]);
			}
			if(-1==_url.indexOf("?")){
				_url += "?"+arr.join('&');
			}else{
				_url += "&"+arr.join('&');
			}
			_combobox = $('#'+_id).combobox({
	            url:_url,
	            editable:_editable,
	            valueField:_idField,
	            textField:_textField,
	            width:_width,
	            panelWidth:_panelWidth,
	            panelHeight:_panelHeight,
	            multiple:_multiple,
	            separator:_separator,
	            required:_required,
		        editable:_editable,
		        isDefaultOption:_isDefaultOption,
				missingMessage:_missingMessage,
				tipPosition:_tipPosition,
	            onShowPanel:function(){
					_onShowPanel();
				},
	            onChange:function(newValue, oldValue){
					_onChange(newValue, oldValue);
				},
	            onHidePanel:function() {
					$('#'+_id).val($('#'+_id).combobox('getValues'));
					_onHidePanel();	
				},
				onLoadSuccess:function(data){
					var datas = $('#'+_id).combobox('getData');
					if(!$('#'+_id).combobox("options").isDefaultOption&&_defaultOption){
						var _jstr = '{'+_idField+':"",'+_textField+':"'+_defaultOption+'"}';
						var _jd = $.str2json(_jstr);
						var _narr = [];
						_narr.push(_jd);
						datas = _narr.concat(datas);
						$('#'+_id).combobox("options").isDefaultOption = true;
						$('#'+_id).combobox("loadData", datas);
						return false;
					}
					if(_initvalue){
						_initvalue = _initvalue+'';
						//如果有初始值，同事，列表选项不为空
						var _arr = _initvalue.split(',');
						for(var i=0;i<_arr.length;i++){
							for(var j=0;j<datas.length;j++){
								if(_arr[i]==datas[j][_idField]){
									$('#'+_id).combobox('select',_arr[i]);
								}
							}
						}
					}else{
						//如果没有初始值，同时_isinitselect设定为true，则自动选择第一条记录
						if(_isinitselect){
							if(datas.length>0){
								$('#'+_id).combobox('select',datas[0][_idField]);
							}
						}
					}
					if(_required){
						$('#'+_id).combobox('validate');
					}
					if(!data){
						data = {};
					}
					_onLoadSuccess(data);
			    },
			    onLoadError:function(XMLHttpRequest, textStatus, errorThrown){
			    	_onLoadError(XMLHttpRequest, textStatus, errorThrown);
			    },
			    onSelect:function(record){
			    	_onSelect(record);
			    },
			    onUnselect:function(record){
			    	_onUnselect(record);
			    }
	        });
		}else{
			_combobox = $('#'+_id).combobox({
				data:_data,
	            editable:_editable,
	            editable:_editable,
	            valueField:_idField,
	            textField:_textField,
	            width:_width,
	            panelWidth:_panelWidth,
	            panelHeight:_panelHeight,
	            multiple:_multiple,
	            separator:_separator,
	            required:_required,
		        editable:_editable,
				missingMessage:_missingMessage,
				tipPosition:_tipPosition,
	            
	            onShowPanel:function(){
					_onShowPanel();
				},
	            onChange:function(newValue, oldValue){
					_onChange(newValue, oldValue);
				},
	            onHidePanel:function() {
					$('#'+_id).val($('#'+_id).combobox('getValues'));
					_onHidePanel();	
				},
				onLoadSuccess:function(data){
					var datas = $('#'+_id).combobox('getData');
					if(!$('#'+_id).combobox("options").isDefaultOption&&_defaultOption){
						var _jstr = '{'+_idField+':"",'+_textField+':"'+_defaultOption+'"}';
						var _jd = $.str2json(_jstr);
						var _narr = [];
						_narr.push(_jd);
						datas = _narr.concat(datas);
						$('#'+_id).combobox("options").isDefaultOption = true;
						$('#'+_id).combobox("loadData", datas);
						return false;
					}
					if(_initvalue){
						//如果有初始值，同事，列表选项不为空
						var _arr = _initvalue.split(',');
						for(var i=0;i<_arr.length;i++){
							for(var j=0;j<datas.length;j++){
								if(_arr[i]==datas[j][_idField]){
									$('#'+_id).combobox('select',_arr[i]);
								}
							}
						}
					}
					if(_required){
						$('#'+_id).combobox('validate');
					}
					if(!data){
						data = {};
					}
					_onLoadSuccess(data);
			    },
			    onLoadError:function(XMLHttpRequest, textStatus, errorThrown){
			    	_onLoadError(XMLHttpRequest, textStatus, errorThrown);
			    },
			    onSelect:function(record){
			    	_onSelect(record);
			    },
			    onUnselect:function(record){
			    	_onUnselect(record);
			    }
	        });
		}
		return _combobox;
	},
	combobox_setValue:function(jparam){
		var _id = jparam.id;
		var _value = jparam.value;
		$('#'+_id).combobox('setValue',_value);
		$('#'+_id).combobox('validate');
	},
	combobox_setValues:function(jparam){
		var _id = jparam.id;
		var _value = jparam.value;
		$('#'+_id).combobox('setValues',_value);
		$('#'+_id).combobox('validate');
	},
	combobox_clear:function(jparam){
		var _id = jparam.id;
		$.combobox_setValue({id:_id,value:''});
	},
	combobox_getValue:function(jparam){
		var _id = jparam.id;
		var _v = $('#'+_id).combobox('getValues');
		_v = _v.join(',');
		return _v;
	},
	combobox_getText:function(jparam){
		var _id = jparam.id;
		var _v = $('#'+_id).combobox('getText');
		return _v;
	},
	combobox_disabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).combobox('disable');
	},
	combobox_enabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).combobox('enable');
	},
	//下拉grid选择控件
	combogrid:function(jparam){
		//1、读取所有参数
		var _gridcode = jparam.gridcode?jparam.gridcode:_DEFAULT_gridcode;
		var _id = jparam.id?jparam.id:$.getID();
		
		var _initvalue = jparam.initvalue?jparam.initvalue:'';
		var _inittext = jparam.inittext?jparam.inittext:'';
        
		var _panelWidth = jparam.panelWidth?jparam.panelWidth:'auto';
		var _panelHeight = jparam.panelHeight?jparam.panelHeight:'auto';
		var _striped = jparam.striped?jparam.striped:true;						//是否隔行颜色不同
		var _rownumbers = (false==jparam.rownumbers)?jparam.rownumbers:true;	//是否显示行号
		var _fit = (false==jparam.fit)?jparam.fit:true;							//自动大小
		var _url = jparam.url?jparam.url:'';									//数据获取URL
		var _queryParams = jparam.queryParams?jparam.queryParams:{};			//请求参数
		var _method = jparam.method?jparam.method:'post';						//http请求方式
		var _multiple = (true==jparam.multiple)?jparam.multiple:false;			//是否多选  
		var _checkbox = (true==jparam.checkbox)?jparam.checkbox:false;			//是否显示checkbox
		var _pageSize = jparam.pageSize?jparam.pageSize:10;						//分页每页记录数
		var _pageList = jparam.pageList?jparam.pageList:[10,20,30,40,50];		//每页记录数列表
		var _loadMsg = jparam.loadMsg?jparam.loadMsg:'正在加载数据...';			//数据加载提示信息
		var _idField = jparam.idField?jparam.idField:'';						//返回隐藏字段
		var _textField = jparam.textField?jparam.textField:'';					//返回显示字段
		var _pagination = (true==jparam.pagination)?jparam.pagination:false;			//是否显示分页控件  
		var _columns = jparam.columns?jparam.columns:[];						//表头
		
		
		var _required = (true==jparam.required)?jparam.required:false;
		var _editable = (false==jparam.editable)?jparam.editable:true;
		var _missingMessage = jparam.missingMessage?jparam.missingMessage:'该项不能为空';
		var _tipPosition = jparam.tipPosition?jparam.tipPosition:'bottom';
		
		
		//1、从后台读取grid配置以及个人默认样式，然后附加datagrid属性
		//var _data = [{name:"gridcode",value:_gridcode}];
		var _data = {gridcode:_gridcode};
		$.cuajax({
		  	url:'wdk?action=wdk.public&method=grid_init&ajaxparam='+new Date().getTime(),
			method:"post", 
			timeout:WDK_Timeout,
			data:_data,   
			success:function(result) {
				var jparam = eval('('+result+')');
				try{
					_cg_initGrid(jparam);
				}catch(e){
//					alert(e.message);
					$.getRoot().$.messager.alert('信息提示','combogrid加载失败'+e.message,'error');
				}
			},
			error:function(result){
//				alert('网络错误！result='+result);
				$.getRoot().$.messager.alert('信息提示','网络错误：'+result,'error');
			}
		});
		//2、请求表头参数
		
		function _cg_initGrid(jparam){
			if(_columns.length<1){
				var arr = [];
				for(var i=0;i<jparam.fields.length;i++){
					var jfield = jparam.fields[i];
					var jc = new Object();
					jc.field = jfield.fieldcode;
					jc.title = jfield.fieldname;
					jc.width = jfield.width;
					arr.push(jc);
				}
				_columns.push(arr);
			}
			if(_checkbox){
				var jck = new Object();
				jck.field = 'ck';
				jck.checkbox = true;
				var arrtmp = [];
				arrtmp.push(jck);
				_columns[0] = arrtmp.concat(_columns[0]);
			}
			
			if(!_queryParams.orderbyfield){
				_queryParams.orderbyfield = _idField;
			}
			//3、加载combogrid
			$('#'+_id).attr('isrequired',_required);
			$('#'+_id).combogrid({  
		        panelWidth:_panelWidth,     
		        panelHeight:_panelHeight,
		        rownumbers:_rownumbers,			//序号     
		        fit:_fit,						//自动大小     
		        striped:_striped,
		        pagination:_pagination,         //启用分页控件  
		        pageSize:_pageSize,     		//每页显示的记录条数，默认为50  
		        pageList:_pageList,         	//可以设置每页记录条数的列表  
		        loadMsg: _loadMsg,           	//当从远程站点加载数据时，显示的提示信息。  
		        idField:_idField,  
		        textField:_textField,
		        multiple: _multiple,
		        url:_url,  						//http请求URL地址
		        queryParams:_queryParams,
		        method:_method,					//http请求方式，post或get     			
		        columns:_columns,
		        required:_required,
		        editable:_editable,
				missingMessage:_missingMessage,
				tipPosition:_tipPosition,
				onSelect:function(rowIndex, rowData) {
					$('#'+_id).val(rowData[_idField]);
				},
				onSortColumn:function(sort,order){  
		             $(this).combogrid('options').queryParams.orderbyfield = sort+' '+order;
		             var _queryParams = $(this).combogrid('options').queryParams;
		             $(this).combogrid({queryParams:_queryParams});
		         }
		    }); 
			//设置默认值
			$('#'+_id).combogrid('setValue', _initvalue).combogrid('setText', _inittext);
		}
	},
	//下来树控件
	combotree:function(jparam){
		var _id = jparam.id?jparam.id:$.getID();
		var _url = jparam.url?jparam.url:'';
		var _initvalue = jparam.initvalue?jparam.initvalue:'';
		var _asyn = (true==jparam.asyn)?jparam.asyn:false;			//是否为异步，默认为同步
		var _multiple = (true==jparam.multiple)?jparam.multiple:false;	//是否多选
		var _valueField = jparam.valueField?jparam.valueField:'';
		var _textField = jparam.textField?jparam.textField:'';
		var _onClick = jparam.onClick?jparam.onClick:function(){};
		var _onLoadSuccess = jparam.onLoadSuccess?jparam.onLoadSuccess:function(){};
		var _onBeforeExpand = jparam.onBeforeExpand?jparam.onBeforeExpand:function(){};
		var _required = (true==jparam.required)?jparam.required:false;
		var _editable = (false==jparam.editable)?jparam.editable:true;
		var _missingMessage = jparam.missingMessage?jparam.missingMessage:'该项不能为空';
		var _tipPosition = jparam.tipPosition?jparam.tipPosition:'bottom';
		
		var _sa = '0';
		if(_asyn){
			_sa = '1';
		}
		_url += _url.match(/\?/) ? (_url.match(/\=/)?"&asyn="+_sa:"asyn="+_sa) : ("?asyn="+_sa);

		$('#'+_id).attr('isrequired',_required);
		$('#'+_id).combotree({
			url:_url,
            valueField:_valueField,
            textField:_textField,
            required:_required,
	        editable:_editable,
			missingMessage:_missingMessage,
			tipPosition:_tipPosition,
            onClick:_onClick,
            multiple:_multiple,
            onLoadSuccess: function (node, data) {
                $('#'+_id).combotree('tree').tree("collapseAll"); 
              //设置默认选中
        		var arr = _initvalue.split(",");
        		for(var i=0;i<arr.length;i++){
        			var node = $("#"+_id).combotree('tree').tree('find',arr[i]);
        		//	alert(arr[i]+"="+node)
        			if(node){
        				$("#"+_id).combotree('tree').tree('check',node.target);
        			}
        		}
            },
            onBeforeExpand:function(node) {
            	if(_asyn){
            	//	alert('onBeforeExpand  nodeid='+node.id)
            		var _asynurl = _url + '&nodeid='+node.id;
            		$('#'+_id).combotree("tree").tree("options").url = _asynurl;
            	}
            },
            onHidePanel: function(node){
            	var nodes = $('#'+_id).combotree('tree').tree('getChecked');
                var s = '';
                for (var i = 0; i < nodes.length; i++) {
                    if (s != '') 
                        s += ',';
                    s += nodes[i].id;
                }
            	$('#'+_id).val(s);  
            } 
		});
		
		
	},
	//输入弹出框
	inputpop:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _type = jparam.type?jparam.type:'';
		
		var _initvalue = jparam.initvalue?jparam.initvalue:'';
		var _inittext = jparam.inittext?jparam.inittext:'';
		var _initid = jparam.initid?jparam.initid:null;
		if(!_initid){
			_initid = _initvalue;
		}
		var _required = (true==jparam.required)?jparam.required:false;			//是否必须
		var _editable = (false==jparam.editable)?jparam.editable:true;			//是否允许编辑
		var _keyHandler = jparam.keyHandler?jparam.keyHandler:{};
		var istakevalue = (true==jparam.istakevalue)?jparam.istakevalue:false; //是否传递文本值到URL中
		//注册事件，注册方法，然后以methodid作为参数传递
		
		
		var _onBeforeOpen_mid = '';		//(null==_onBeforeOpen)?'':$.method_reg(window,_onBeforeOpen);
		var _callback_mid = '';			//(null==_callback)?'':$.method_reg(window,_callback);
		var _onChangeValue_mid = '';
		var _onLoadSuccess_mid = '';
		
		var _onChangeValue = jparam.onChangeValue;
		if(_onChangeValue){
			if('string'==typeof(_onChangeValue)&&_onChangeValue.length==32){
				_onChangeValue_mid = _onChangeValue;
			}else{
				_onChangeValue = $.event_getHandler(_onChangeValue);
				_onChangeValue_mid = $.method_reg(window,_onChangeValue);
			}
		}else{
			_onChangeValue = null;
			_onChangeValue_mid = '';
		}
		
		
		var _onBeforeOpen = jparam.onBeforeOpen;
		if(_onBeforeOpen){
			if('string'==typeof(_onBeforeOpen)&&_onBeforeOpen.length==32){
				_onBeforeOpen_mid = _onBeforeOpen;
			}else{
				_onBeforeOpen = $.event_getHandler(_onBeforeOpen);
				_onBeforeOpen_mid = $.method_reg(window,_onBeforeOpen);
			}
		}else{
			_onBeforeOpen = null;
			_onBeforeOpen_mid = '';
		}
			
		var _callback = jparam.callback;
		if(_callback){
			if('string'==typeof(_callback)&&_callback.length==32){
				_callback_mid = _callback;
			}else{
				_callback = $.event_getHandler(jparam.callback);
				_callback_mid = $.method_reg(window,_callback);
			}
		}else{
			_callback = null;
			_callback_mid = '';
		}
		
		
		var _onLoadSuccess = jparam.onLoadSuccess;
		if(_onLoadSuccess){
			if('string'==typeof(_onLoadSuccess)&&_onLoadSuccess.length==32){
				_onLoadSuccess_mid = _onLoadSuccess;
			}else{
				_onLoadSuccess = $.event_getHandler(jparam.onLoadSuccess);
				_onLoadSuccess_mid = $.method_reg(window,_onLoadSuccess);
			}
		}else{
			_onLoadSuccess = null;
			_onLoadSuccess_mid = '';
		}
		
		//对key增加默认的回车弹出键
		_keyHandler['enter'] = function(jparam){
//			alert('回车  id='+jparam.id)
			$.inputpop_open({id:jparam.id});
		};
		
		var _keyHandler_new = new Object();
		for(var shortkey in _keyHandler){
			var _handler = _keyHandler[shortkey];
			var _handler_mid = "";
			if(_handler){
				if('string'==typeof(_handler)&&_handler.length==32){
					_handler_mid = _handler;
				}else{
					_handler = $.event_getHandler(_handler);
					_handler_mid = $.method_reg(window,_handler);
				}
			}else{
				_handler = null;
				_handler_mid = '';
			}
			var ks = shortkey+'';
			_keyHandler_new[ks] = _handler_mid;
		}
		
		
		
		jparam.onBeforeOpen = _onBeforeOpen_mid;
		jparam.callback = _callback_mid;
		jparam.onChangeValue = _onChangeValue_mid;
		jparam.onLoadSuccess = _onLoadSuccess_mid;
		jparam.keyHandler = _keyHandler_new;
		
		switch(_type){
			case 'datetime':
				css_arrow = 'inputpop_arrow_date';
				jparam.url = WDK_ROOT+'/module/public/inputpop_datetime.jsp';
				break;
			case 'date':
				css_arrow = 'inputpop_arrow_date';
				jparam.url = WDK_ROOT+'/module/public/inputpop_date.jsp';
				break;
			case 'select':
				jparam.url = WDK_ROOT+'/module/public/inputpop_select.jsp';
				break;
			case 'tree':
				jparam.url = WDK_ROOT+'/module/public/inputpop_tree.jsp';
				break;
			case 'treegrid':
				jparam.url = WDK_ROOT+'/module/public/inputpop_treegrid.jsp';
				break;
			case 'grid':
				jparam.url = WDK_ROOT+'/module/public/inputpop_grid.jsp';
				break;
			case 'week':
				jparam.url = WDK_ROOT+'/module/public/inputpop_week.jsp';
				break;
			default:
				break;
		}
		
		var _url = jparam.url?jparam.url:'';
		var _param = jparam.param?jparam.param:{};
		
		
		var _obj = document.getElementById(_id);
		var _width = _obj.clientWidth;
		var _height = _obj.clientHeight;
		var _name = _obj.name;
		var _strparam = $.json2str(jparam);
		_strparam = _strparam.replace(/\'/ig,"\\\'").replace(/\"/ig,"\\\'");
		
		var _class = 'inputpop_input';
		if(!_inittext&&_required){
			_class = 'inputpop_input_required';
		}
		var _readonly = (false==_editable)?'readonly ':' ';
		
		var cstr = '<span class="inputpop_span" id="inputpop_span_'+_id+'" style="width:'+_width+'px;height:'+_height+'px;">'
			+'			<input class="'+_class+'" isrequired="'+_required+'" id="'+_id+'" '
			+'					name="'+_name+'" value="'+_inittext+'" '
		//	+'					onfocusin="_inputpop_onfocusin(\''+_id+'\')" '
		//	+'					onfocusout="_inputpop_onfocusout(\''+_id+'\')" '
			+'					onkeydown="_inputpop_onkeydown(\''+_id+'\',this,event,\''+_strparam+'\')"'
			+'					onfocus="_inputpop_onfocusin(\''+_id+'\');this.select();" '
			+'					onblur="_inputpop_onfocusout(\''+_id+'\')" '
			+					_readonly
			+'					style="width:'+(_width-25)+'px;height:'+_height+'px;line-height:'+_height+'px;" type="text" autocomplete="off"/>'
			+'			<span class="inputpop_arrow_span">'
			+'				<span class="inputpop_arrow" style="height: 20px;" onclick="_inputpop_openwin(\''+_id+'\')"/>'
			+'				<input id="iph_param_'+_id+'" type="hidden" value="'+_strparam+'"/>'
			+'			</span>'
			+'			<input class="inputpop_hidden_istakevalue" id="iph_istakevalue_'+_id+'" type="hidden" value="'+istakevalue+'"/>'
			+'			<input class="inputpop_hidden_name" id="iph_text_'+_id+'" type="hidden" value="'+_inittext+'"/>'
			+'			<input class="inputpop_hidden_value" id="iph_value_'+_id+'" type="hidden" value="'+_initvalue+'"/>'
			+'			<input class="inputpop_hidden_id" id="iph_id_'+_id+'" type="hidden" value="'+_initid+'"/>'
			+'			<input class="inputpop_hidden_submit" id="iph_submit_'+_id+'" type="hidden" value="'+_initid+'"/>'
			+'		</span>';
		_obj.outerHTML = cstr;
		
		//加载完毕调用
	//	alert(22323);
	//	alert('_onLoadSuccess_mid='+_onLoadSuccess_mid);
		$.method_call(_onLoadSuccess_mid,jparam);
	},
	inputpop_open:function(jparam){
		var _id = jparam.id;
		_inputpop_openwin(_id);
	},
	
	//输入弹出框
	inputpop_smart:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _type = jparam.type?jparam.type:'';
		
		var _initvalue = jparam.initvalue?jparam.initvalue:'';
		var _inittext = jparam.inittext?jparam.inittext:'';
		var _initid = jparam.initid?jparam.initid:null;
		if(!_initid){
			_initid = _initvalue;
		}
		var _required = (true==jparam.required)?jparam.required:false;			//是否必须
		var _editable = (false==jparam.editable)?jparam.editable:true;			//是否允许编辑
		var _keyHandler = jparam.keyHandler?jparam.keyHandler:{};
		
		//注册事件，注册方法，然后以methodid作为参数传递
		
		
		var _onBeforeOpen_mid = '';		//(null==_onBeforeOpen)?'':$.method_reg(window,_onBeforeOpen);
		var _callback_mid = '';			//(null==_callback)?'':$.method_reg(window,_callback);
		var _onChangeValue_mid = '';
		var _onLoadSuccess_mid = '';
		
		var _onChangeValue = jparam.onChangeValue;
		if(_onChangeValue){
			if('string'==typeof(_onChangeValue)&&_onChangeValue.length==32){
				_onChangeValue_mid = _onChangeValue;
			}else{
				_onChangeValue = $.event_getHandler(_onChangeValue);
				_onChangeValue_mid = $.method_reg(window,_onChangeValue);
			}
		}else{
			_onChangeValue = null;
			_onChangeValue_mid = '';
		}
		
		
		var _onBeforeOpen = jparam.onBeforeOpen;
		if(_onBeforeOpen){
			if('string'==typeof(_onBeforeOpen)&&_onBeforeOpen.length==32){
				_onBeforeOpen_mid = _onBeforeOpen;
			}else{
				_onBeforeOpen = $.event_getHandler(_onBeforeOpen);
				_onBeforeOpen_mid = $.method_reg(window,_onBeforeOpen);
			}
		}else{
			_onBeforeOpen = null;
			_onBeforeOpen_mid = '';
		}
			
		var _callback = jparam.callback;
		if(_callback){
			if('string'==typeof(_callback)&&_callback.length==32){
				_callback_mid = _callback;
			}else{
				_callback = $.event_getHandler(jparam.callback);
				_callback_mid = $.method_reg(window,_callback);
			}
		}else{
			_callback = null;
			_callback_mid = '';
		}
		
		
		var _onLoadSuccess = jparam.onLoadSuccess;
		if(_onLoadSuccess){
			if('string'==typeof(_onLoadSuccess)&&_onLoadSuccess.length==32){
				_onLoadSuccess_mid = _onLoadSuccess;
			}else{
				_onLoadSuccess = $.event_getHandler(jparam.onLoadSuccess);
				_onLoadSuccess_mid = $.method_reg(window,_onLoadSuccess);
			}
		}else{
			_onLoadSuccess = null;
			_onLoadSuccess_mid = '';
		}
		
		//对key增加默认的回车弹出键
		_keyHandler['enter'] = function(jparam){
//			alert('回车  id='+jparam.id)
			$.inputpop_open_s({id:jparam.id});
		};
		
		var _keyHandler_new = new Object();
		for(var shortkey in _keyHandler){
			var _handler = _keyHandler[shortkey];
			var _handler_mid = "";
			if(_handler){
				if('string'==typeof(_handler)&&_handler.length==32){
					_handler_mid = _handler;
				}else{
					_handler = $.event_getHandler(_handler);
					_handler_mid = $.method_reg(window,_handler);
				}
			}else{
				_handler = null;
				_handler_mid = '';
			}
			var ks = shortkey+'';
			_keyHandler_new[ks] = _handler_mid;
		}
		
		
		
		jparam.onBeforeOpen = _onBeforeOpen_mid;
		jparam.callback = _callback_mid;
		jparam.onChangeValue = _onChangeValue_mid;
		jparam.onLoadSuccess = _onLoadSuccess_mid;
		jparam.keyHandler = _keyHandler_new;
		
		switch(_type){
			case 'datetime':
				css_arrow = 'inputpop_arrow_date';
				jparam.url = WDK_ROOT+'/module/public/inputpop_datetime.jsp';
				break;
			case 'date':
				css_arrow = 'inputpop_arrow_date';
				jparam.url = WDK_ROOT+'/module/public/inputpop_date.jsp';
				break;
			case 'select':
				jparam.url = WDK_ROOT+'/module/public/inputpop_select.jsp';
				break;
			case 'tree':
				jparam.url = WDK_ROOT+'/module/public/inputpop_tree.jsp';
				break;
			case 'treegrid':
				jparam.url = WDK_ROOT+'/module/public/inputpop_treegrid.jsp';
				break;
			case 'grid':
				jparam.url = WDK_ROOT+'/module/public/inputpop_grid.jsp';
				break;
			case 'week':
				jparam.url = WDK_ROOT+'/module/public/inputpop_week.jsp';
				break;
			default:
				break;
		}
		var _url = jparam.url?jparam.url:'';
		var _param = jparam.param?jparam.param:{};
		
		
		var _obj = document.getElementById(_id);
		var _width = _obj.clientWidth;
		var _height = _obj.clientHeight;
		var _name = _obj.name;
		var _strparam = $.json2str(jparam);
		_strparam = _strparam.replace(/\'/ig,"\\\'").replace(/\"/ig,"\\\'");
		
		var _class = 'inputpop_input';
		if(!_inittext&&_required){
			_class = 'inputpop_input_required';
		}
		var _readonly = (false==_editable)?'readonly ':' ';
		
		var cstr = '<span class="inputpop_span" id="inputpop_span_'+_id+'" style="width:'+_width+'px;height:'+_height+'px;">'
			+'			<input class="'+_class+'" isrequired="'+_required+'" id="'+_id+'" '
			+'					name="'+_name+'" value="'+_inittext+'" '
		//	+'					onfocusin="_inputpop_onfocusin(\''+_id+'\')" '
		//	+'					onfocusout="_inputpop_onfocusout(\''+_id+'\')" '
			+'					onkeydown="_inputpop_onkeydown(\''+_id+'\',this,event,\''+_strparam+'\')"'
			+'					onfocus="_inputpop_onfocusin(\''+_id+'\');this.select();" '
			+'					onblur="_inputpop_onfocusout(\''+_id+'\')" '
			+					_readonly
			+'					style="width:'+(_width-25)+'px;height:'+_height+'px;line-height:'+_height+'px;" type="text" autocomplete="off"/>'
			+'			<span class="inputpop_arrow_span">'
			+'				<span class="inputpop_arrow" style="height: 20px;" onclick="_inputpop_openwin_s(\''+_id+'\')"/>'
			+'				<input id="iph_param_'+_id+'" type="hidden" value="'+_strparam+'"/>'
			+'			</span>'
			+'			<input class="inputpop_hidden_name" id="iph_text_'+_id+'" type="hidden" value="'+_inittext+'"/>'
			+'			<input class="inputpop_hidden_value" id="iph_value_'+_id+'" type="hidden" value="'+_initvalue+'"/>'
			+'			<input class="inputpop_hidden_id" id="iph_id_'+_id+'" type="hidden" value="'+_initid+'"/>'
			+'			<input class="inputpop_hidden_submit" id="iph_submit_'+_id+'" type="hidden" value="'+_initid+'"/>'
			+'		</span>';
		_obj.outerHTML = cstr;
		
		//加载完毕调用
		$.method_call(_onLoadSuccess_mid,jparam);
	},	
	inputpop_open_s:function(jparam){
		var _id = jparam.id;
		_inputpop_openwin_s(_id);
	},	
	inputpop_getOptions:function(jparam){
		var _id = jparam.id;
		var strparam = $('#iph_param_'+_id).val();
		strparam = strparam.replace(/\\\'/ig,"\'");
		var jparam =$.str2json(strparam);
		return jparam;
	},
	inputpop_setOptions:function(jparam){
		var _id = jparam.id;
		var _opts = jparam.options;
		var _strparam = $.json2str(_opts);
		_strparam = _strparam.replace(/\'/ig,"\\\'").replace(/\"/ig,"\\\'");
		$('#iph_param_'+_id).val(_strparam);
	},
	inputpop_getValue:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var v = $("#iph_id_"+_id).val();
		return v;
	},
	//返回通过选择的内容，如果不点击确定则取值为空
	inputpop_getValueBySelect:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var value_id = $("#iph_id_"+_id).val();
		var value_submit = $("#iph_submit_"+_id).val();
		
		//相同说明是通过点击确定选择的
		if(value_id==value_submit){
			return value_id;
		}else{
			return '';
		}
	},
	inputpop_getValues:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var v = new Object();
		v.value_id = $("#iph_id_"+_id).val();
		v.value_text = $("#iph_text_"+_id).val();
		v.value_value = $("#iph_value_"+_id).val();
		return v;
	},
	//返回通过选择的内容，如果不点击确定则取值为空
	inputpop_getValuesBySelect:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var v = new Object();
		
		var value_id = $("#iph_id_"+_id).val();
		var value_text = $("#iph_text_"+_id).val();
		var value_value = $("#iph_value_"+_id).val();
		var value_submit = $("#iph_submit_"+_id).val();
		
		//相同说明是通过点击确定选择的
		if(value_id==value_submit){
			v.value_id = value_id;
			v.value_text = value_text;
			v.value_value = value_value;
		}else{
			v.value_id = '';
			v.value_text = '';
			v.value_value = '';
		}
		return v;
	},
	inputpop_setValue:function(jparam){
		var _id = jparam.id?jparam.id:'';
		var _value_id = jparam.value_id?jparam.value_id:(jparam.initid?jparam.initid:"");
		var _value_text = jparam.value_text?jparam.value_text:(jparam.inittext?jparam.inittext:"");
		var _value_value = jparam.value_value?jparam.value_value:(jparam.initvalue?jparam.initvalue:"");
		
		$('#'+_id).val(_value_text);
		$('#iph_id_'+_id).val(_value_id);
		$('#iph_text_'+_id).val(_value_text);
		$('#iph_value_'+_id).val(_value_value);
		
		if('true'==$('#'+_id).attr('isrequired')){
			if(_value_id){
				$('#'+_id).attr('class','inputpop_input');
			}else{
				$('#'+_id).attr('class','inputpop_input_required');
			}
		}
	},
	//清除inputpop的值
	inputpop_clear:function(jparam){
		var _id = jparam.id;
		$.inputpop_setValue({id:_id,value_id:'',value_text:'',value_value:''});
	},
	//禁用inputpop
	inputpop_disabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).attr("disabled","disabled");
		$('#'+_id+'_arrow_show').css("display","none");
		$('#'+_id+'_arrow_hidden').attr("display","block");
	},
	//启用inputpop控件
	inputpop_enabled:function(jparam){
		var _id = jparam.id;
		$('#'+_id).removeAttr("disabled");
		$('#'+_id+'_arrow_show').css("display","block");
		$('#'+_id+'_arrow_hidden').attr("display","none");
	},
	
	//触发弹出窗口的确定事件
	inputpop_event_submit:function(){
		var mid_sub = $.getURLParam('mid_sub');
		$.method_call(mid_sub);
	},
	//触发弹出窗口的清除事件
	inputpop_event_clear:function(){
		var mid_clr = $.getURLParam('mid_clr');
		$.method_call(mid_clr);
	},
	//触发弹出窗口的退出事件
	inputpop_event_cancel:function(){
		var mid_can = $.getURLParam('mid_can');
		$.method_call(mid_can);
	},
	
	
	
	//触发弹出窗口的确定事件
	dialog_event_submit:function(){
		var mid_sub = $.getURLParam('mid_sub');
		$.method_call(mid_sub);
	},
	//触发弹出窗口的退出事件
	dialog_event_cancel:function(){
		var mid_can = $.getURLParam('mid_can');
		$.method_call(mid_can);
	},
	
	/*********************************************
	 * 				打印控件及相关方法
	 *********************************************/
	//打开设计器
	print_design:function(jparam){
		var _top = $.getRoot();
		_top.print_design(jparam);

	},
	//打印预览
	print_preview:function(jparam){
		
		var _wid = $.getUUID();
		$.openWin({
			id:_wid,
			title:'打印预览',
			height:300,
			width:400,
			modal:true,
			type:'url',
			url:WDK_ROOT+'/module/frame/public/print_preview.jsp',
			queryParams:jparam,
			maximized:true,
			maximizable:true
		});
	},
	//直接打印
	print_print:function(jparam){
		
		if(confirm('是否确定打印？')){
			var _top = $.getRoot();
			_top.print_print(jparam);
		}
	},
	//直接打印
	print_print11:function(jparam){
		
		if(confirm('是否确定打印？')){
			var _top = $.getRoot();
			_top.print_print11(jparam);
		}
	},
	//打印维护
	print_setup:function(jparam){
		var _top = $.getRoot();
		_top.print_setup(jparam);
	},
	
	//打印模板解析，固位单表分页连打
	print_translate_gw_db_fy_ld:function(cmdStr,jdata,pageStart){
		if(!cmdStr||!jdata){
			return cmdStr;
		}
		
		var trNum = 0;					//总行数
		var tdNum = 0;					//总列数
		var pageNum = 0;				//每页记录数
		var totalPage = 0;				//总页数
		var footerHTML = '';			//最末行的html
		
		//1、替换<table>....</table>为固定字符maintb
		var reg = /<table.*\/table>/ig;
		if(reg.test(cmdStr)){
			var tbhtml = cmdStr.match(reg)+'';
			tbhtml = tbhtml.replace(/\\n/ig,'').replace(/\\/ig,'');
			var _tb = $(tbhtml);
			var _tb_style = _tb.attr('style');
			var _tr_height = "";
			
			//清空tbhtml的内容，准备构建新的table html
			tbhtml = [];
			
			//2、对table进行操作
			//tbhtml.push('<table border=\\"1\\" style=\\"border: 1px solid black;font-size:10px;border-style: solid;border-collapse: collapse;table-layout:fixed;word-break:break-all;\\">');
			
			tbhtml.push('<table border=\\"1\\" style=\\"'+_tb_style+'\\">');
			
			//2.1、构建表头
			_tb.find("tr").each(function(){
				if(0==trNum){
					//当前是表头行
					var trhtml = $(this).html();
					trhtml = trhtml.replace(/\"/ig,'\\\"').replace(/[\r]/ig,"").replace(/[\n]/ig,"");
					tbhtml.push('<tr height=\\"32px\\">'+trhtml+'</tr>');
					tdNum = 0;
					$(this).find("td").each(function(){
						tdNum++;
					});
				}
				if(1==trNum){
					//如果当前是第二行，即内容体
					_tr_height = $(this).attr('height');
				//	alert('_tr_height='+_tr_height)
				}
				footerHTML = $(this).html();
				trNum++;
			});
			
			pageNum = trNum-2;

			footerHTML = '<tr height="32px">'+footerHTML+'</tr>';
			//2.2、计算需要进行统计的字段
			var _total = new Object();			//统计
			var _formats = new Object();		//格式化
			$(footerHTML).find("td").each(function(){
				var _tdtxt = $(this).text();
				var _format = $(this).attr('format');
				_format = _format?_format:'#,##0.00';
				
				if(/[$]\{.*\}/.test(_tdtxt)){
					var _txt = /[$]\{.*\}/.exec(_tdtxt)+'';
					_txt = _txt.replace(/[\$\{\}]/ig,'');
					var _totalcol = _txt.split('.')[1];
					
					_total[_totalcol] = '0';
					_formats[_totalcol] = _format;
				}
			});
			
			//2.3、构建内容体
			var jdetail = jdata.detail;
			totalPage = Math.ceil(parseFloat(jdetail.length)/parseFloat(pageNum));
			if(jdetail.length<=pageStart*pageNum){
				return null;
			}
			for(var i=pageStart*pageNum;i<(pageStart+1)*pageNum;i++){
				tbhtml.push('<tr height=\\"'+_tr_height+'px\\">');
				var jrow = jdetail[i];
				if(!jrow){
					for(var j=0;j<tdNum;j++){
						tbhtml.push('<td align=\\"center\\">&nbsp;</td>');
					}
				}else{
					var num = 1;
					for(var att in jrow){
						if(num<=tdNum){
							tbhtml.push('<td align=\\"center\\">'+jrow[att]+'</td>');
						}else{
							break;
						}
						num++;
					}
					
					for(var colname in _total){
						if(-1!=colname.indexOf('*')){
							var _arrtmp = colname.split('*');
							var _v0 = jrow[_arrtmp[0]];
							var _v1 = jrow[_arrtmp[1]];
							if(_v0&&_v1){
								_v0 = _v0.replace(/[,]/ig,'').replace(/[L]/ig,'').replace(/[l]/ig,'');
								_v1 = _v1.replace(/[,]/ig,'').replace(/[L]/ig,'').replace(/[l]/ig,'');
								_total[colname] =parseFloat(_total[colname]) + (parseFloat(_v0)*parseFloat(_v1));
							}
						}else{
							var _v = jrow[colname].replace(/[,]/ig,'').replace(/[L]/ig,'').replace(/[l]/ig,'');
							_total[colname] =parseFloat(_total[colname]) + parseFloat(_v);
						}
					}
				}
				tbhtml.push('</tr>');
			}
			
			//添加页脚
			for(var colname in _total){
				var _count = _total[colname];
				
				var _format = _formats[colname];
				
				var _str_cn = $.number2cn(_count);
				footerHTML = footerHTML.replace('${total.'+colname+'.cn}',_str_cn+'');
				
				var _str_en = $.number2en(_count,_format);
				footerHTML = footerHTML.replace('${total.'+colname+'.en}',_str_en+'');
			}
			footerHTML = footerHTML.replace(/\"/ig,'\\\"').replace(/[\r]/ig,"").replace(/[\n]/ig,"");
			tbhtml.push(footerHTML);
			
			tbhtml.push('</table>');
			//替换原table字段为带数据的内容
			cmdStr = cmdStr.replace(reg,tbhtml.join(''));
		}
		
		//2、初始化页码
		jdata['ps'] = (pageStart+1)+'';
		jdata['pe'] = totalPage + '';

		var newStr = cmdStr;
		reg = /[$]\{.*\}/ig;
		while(ret = reg.exec(cmdStr)){
			ret = ret+'';
			var key = ret.replace(/[\$\{\}]/ig,'');
			newStr = newStr.replace(ret,jdata[key]?jdata[key]:'');
		}
		return newStr;
	},
	
	//打印结果集转换，生成打印表格
	print_getTableHtml:function(jparam){
		var _heads = jparam.heads;
		var _rows = jparam.rows;
		var _foothtml = jparam.foothtml;

		var strStyle="<style> table,td,th {border-width: 1px;border-style: solid;border-collapse: collapse}</style>";
		var arr = [];
		arr.push('<table border=1 cellSpacing=0 cellPadding=1 width=\'100%\' style=\'border-collapse:collapse\' bordercolor=\'#333333\'>');
		arr.push('	<thead>');
		arr.push('		<tr>');
		for(var i=0;i<_heads.length;i++){
			var head = _heads[i];
			arr.push('		<td width=\''+head.width+'\'>');
			arr.push('			<div align=center><b>'+head.name+'</b></div>');
			arr.push('		</td>');
		}
		arr.push('		</tr>');
		arr.push('	</thead>');
		arr.push(' 	<tbody>');
		for(var i=0;i<_rows.length;i++){
			var row = _rows[i];
			arr.push('	<tr>');
			for(var j=0;j<_heads.length;j++){
				var head = _heads[j];
				arr.push('	<td>'+row[head.colname]+'</td>');
			}
			arr.push('	</tr>');
		}
		arr.push('	</tbody>');
		if(_foothtml){
			arr.push('	<tfoot>'+_foothtml+'</tfoot>');
		}
		arr.push('</table>');
		return strStyle+arr.join('');
	},
	/*********************************************
	 * 				推式、拉式、上查、下查
	 *********************************************/
	//拉式生成
	pub_query_pull:function(jparam){
		//弹出拉式生成界面
		var _wid = $.getUUID();
		$.openDialog({
			id:_wid,
			title:'拉式生成',
			height:600,
			width:800,
			modal:true,
			type:'url',
			url:WDK_ROOT+'/module/frame/system/pub_query_pull.jsp',
			queryParams:jparam,
			maximized:true,
			maximizable:true,
			onSubmit:function(jparam){
				var _srcinvtype = jparam.pull.srcinvtype;
				var _targetinvtype = jparam.pull.targetinvtype;
				var _srcinvuuidstr = jparam.pull.srcinvuuidstr;
				var _srcinvdtluuidstr = jparam.pull.srcinvdtluuidstr;
				var _targetinvurl = jparam.pull.targetinvurl;
				var _targetinvname = jparam.pull.targetinvname;
				$.cuajax({
					url:'wdk?action=sy.pubquery&method=pub_query_pullAndPush_submit'
					,method:'post'
					,timeout:WDK_Timeout
					,data:jparam.pull
					,success:function(result){
						var jres = $.str2json(result);
						if('1'==jres.code){
							var _datamapuuid = jres.datamapuuid;
							var _targeturl = _targetinvurl;
							if(-1==_targetinvurl.indexOf('?')){
								_targetinvurl += '?DataMapUUID='+_datamapuuid+'&SrcInvType='+_srcinvtype+'&SrcInvUUIDStr='+_srcinvuuidstr;
							}else{
								_targetinvurl += '&DataMapUUID='+_datamapuuid+'&SrcInvType='+_srcinvtype+'&SrcInvUUIDStr='+_srcinvuuidstr;
							}
							
							var _reg  = /menucode=[^\&]+/;
							var _menucode = _reg.exec(_targetinvurl);
							_menucode = _menucode+'';
							if(_menucode){
								_menucode = _menucode.split('=').length>1?_menucode.split('=')[1]:_menucode;
							}else{
								_menucode = 'query_pull';
							}
							
							$.tab_addTop({
								menucode:_menucode
								,title:_targetinvname
								,closable:true
								,url:_targetinvurl
							});

						}else{
//							alert(jres.desc);
							$.getRoot().$.messager.alert('信息提示',jres.desc);
						}
					}
					,error:function(result){
//						alert('操作失败');
						$.getRoot().$.messager.alert('信息提示','操作失败','error');
					}
				});
			}
		});
	},
	//推式生成
	pub_query_push:function(jparam){
		var _wid = $.getUUID();
		$.openDialog({
			id:_wid,
			title:'单据转换',
			height:300,
			width:400,
			modal:true,
			type:'url',
			url:WDK_ROOT+'/module/frame/system/pub_query_push.jsp',
			queryParams:jparam,
			maximized:false,
			maximizable:true,
			onSubmit:function(jparam){
				var _srcinvtype = jparam.pull.srcinvtype;
				var _targetinvtype = jparam.pull.targetinvtype;
				var _srcinvuuidstr = jparam.pull.srcinvuuidstr;
				var _srcinvdtluuidstr = jparam.pull.srcinvdtluuidstr;
				var _targetinvurl = jparam.pull.targetinvurl;
				var _targetinvname = jparam.pull.targetinvname;
				$.cuajax({
					url:'wdk?action=sy.pubquery&method=pub_query_pullAndPush_submit'
					,method:'post'
					,timeout:WDK_Timeout
					,data:jparam.pull
					,success:function(result){
						var jres = $.str2json(result);
						if('1'==jres.code){
							var _datamapuuid = jres.datamapuuid;
							var _targeturl = _targetinvurl;
							if(-1==_targetinvurl.indexOf('?')){
								_targetinvurl += '?DataMapUUID='+_datamapuuid+'&SrcInvType='+_srcinvtype+'&SrcInvUUIDStr='+_srcinvuuidstr;
							}else{
								_targetinvurl += '&DataMapUUID='+_datamapuuid+'&SrcInvType='+_srcinvtype+'&SrcInvUUIDStr='+_srcinvuuidstr;
							}
							var _reg  = /menucode=[^\&]+/;
							var _menucode = _reg.exec(_targetinvurl);
							_menucode = _menucode+'';
							if(_menucode){
								_menucode = _menucode.split('=').length>1?_menucode.split('=')[1]:_menucode;
							}else{
								_menucode = 'query_push';
							}
							
							$.tab_addTop({
								menucode:_menucode
								,title:_targetinvname
								,closable:true
								,url:_targetinvurl
							});

						}else{
//							alert(jres.desc);
							$.getRoot().$.messager.alert('信息提示',jres.desc);
						}
					}
					,error:function(result){
//						alert('操作失败');
						$.getRoot().$.messager.alert('信息提示','操作失败','error');
					}
				});
			}
		});
	},
	//上查
	pub_query_pre:function(jparam){
		var _opentype = jparam.opentype;
		jparam.qrytype = '01';
		var _url = WDK_ROOT+'/module/frame/system/pub_query_PreAndNext.jsp';
		_url += '?param='+$.urlparam_encode($.json2str(jparam));
		if('1'!=_opentype){
			//第一次进来
			var _data = {
					qrytype:'01'
					,srcinvtype:jparam.InvType
					,invuuid:jparam.InvUUID
			};
			$.cuajax({
				url:'wdk?action=sy.pubquery&method=pub_query_PreAndNext&ajaxparam='+new Date().getTime()
				,method:'post'
				,timeout:WDK_Timeout
				,data:_data
				,success:function(result){
					var jres = $.str2json(result);
					if('1'==jres.code){
						var rows = jres.rows;
						if(rows.length>0){
							$.tab_addTop({
								menucode: 'query_pre'
								,title:'关联单据查询'
								,closable:true
								,url:_url
							});
						}else{
							$.getRoot().$.messager.alert('单据查询结果','目标单据为空!','warning');
						}
					}else{
//						alert(jres.desc);
						$.getRoot().$.messager.alert('信息提示',jres.desc);
					}
				}
				,error:function(result){
//					alert('操作失败');
					$.getRoot().$.messager.alert('信息提示','操作失败','error');
				}
			});
		}else{
			$.tab_setTabTop({newurl:_url});
		}
	},
	//下查
	pub_query_next:function(jparam){
		jparam.qrytype = '02';
		var _opentype = jparam.opentype;
		var _url = WDK_ROOT+'/module/frame/system/pub_query_PreAndNext.jsp';
		_url += '?param='+$.urlparam_encode($.json2str(jparam));
		if('1'!=_opentype){
			var _data = {
					qrytype:'02'
					,srcinvtype:jparam.InvType
					,invuuid:jparam.InvUUID
			};
			$.cuajax({
				url:'wdk?action=sy.pubquery&method=pub_query_PreAndNext&ajaxparam='+new Date().getTime()
				,method:'post'
				,timeout:WDK_Timeout
				,data:_data
				,success:function(result){
					var jres = $.str2json(result);
					if('1'==jres.code){
						var rows = jres.rows;
						if(rows.length>0){
							$.tab_addTop({
								menucode: 'query_next'
								,title:'关联单据查询'
								,closable:true
								,url:_url
							});
						}else{
							$.getRoot().$.messager.alert('单据查询结果','目标单据为空!','warning');
						}
					}else{
//						alert(jres.desc);
						$.getRoot().$.messager.alert('信息提示',jres.desc);
					}
				}
				,error:function(result){
//					alert('操作失败');
					$.getRoot().$.messager.alert('信息提示','操作失败','error');
				}
			});
			
		}else{
			$.tab_setTabTop({newurl:_url});
		}
	},

	/*********************************************
	 * 				文档上传、编辑、下载
	 *********************************************/
	//初始化word容器，如果希望初始化打开，则使用fileid
	word_init:function(jparam){
		var id = jparam.id;
		var fileid = jparam.fileid?jparam.fileid:'';
		$.iframe({
				id:'ifr_'+id
				,containerid:id
				,url:WDK_ROOT+'/module/sys/weboffice.jsp?fileid='+fileid
		});
	},
	word_close:function(jparam){
		var id = jparam.id;
		var ifr = document.getElementById('ifr_'+id);
		if(null!=ifr){
			ifr.contentWindow.close();
		}
	},
	//生成word，根据状态为判断是否完成后打开
	word_make:function(jparam){
		$.wait_open();
		var _template = jparam.template;		//wrod模板id
		var _url = jparam.url;					//action处理地址
		var _type = jparam.type;				//处理方式， 0-生成完后给出提示   1-生成完后转到编辑
		var _fileid = jparam.fileid;//?jparam.fileid:$.getUUID();		//fileid前台生成
		var _filename = jparam.filename?jparam.filename:"";
		var _timeout = jparam.timeout?jparam.timeout:WDK_Timeout;
		var _callback = jparam.callback?jparam.callback:function(){};
		_callback = $.event_getHandler(_callback);
		
		var _data = {
					template:_template,
					fileid:_fileid,
					filename:_filename
				};
		
		$.cuajax({
			url:_url
			,method:'post'
			,timeout:_timeout
			,data:_data
			,success:function(result){
				$.wait_close();
				var jres = $.str2json(result);
				if('1'==jres.code){
					if('0'==_type){
						alert('文书生成成功！');
						_callback({fileid:_fileid,code:jres.code,desc:jres.desc});
					}else{
						//转到编辑
						$.word_open(jparam);
					}
				}else{
					alert(jres.desc);
					_callback({fileid:_fileid,code:jres.code,desc:jres.desc});
				}
			}
			,error:function(result){
				$.wait_close();
//				alert('操作失败');
				$.getRoot().$.messager.alert('信息提示','操作失败','error');
			},
			ontimeout:function(){
				$.wait_close();
			}
		});
	},
	//打开已经存在的word
	word_open:function(jparam){
//		var _fileid = jparam.fileid;		//office附件编号
		var _wid = $.getUUID();
		var _callback = jparam.callback?jparam.callback:function(){};
		_callback = $.event_getHandler(_callback);
		var _mid = $.method_reg(window,_callback);
		jparam.callback = '';
		jparam.mid = _mid;
		jparam.wid = _wid;
		$.openWin({
			id:_wid,
			title:'文书编辑',
			height:300,
			width:400,
			modal:true,
			type:'url',
			url:WDK_ROOT+'/module/frame/system/weboffice.jsp',
			queryParams:jparam,
			maximized:true,
			maximizable:true
		});
	},
//	jwplayer('mediaspace').setup({
//    'flashplayer': '<%=WDK_ROOT%>/core/js/lib/jwplayer/player.swf',
//    'file': 'Avengers2.mp4',
//    'streamer': 'rtmp://121.41.114.57/sfsstream',
//    'controlbar': 'bottom',
//    'width': '848',
//    'height': '360'
//  });
	//定义并打开流媒体
	player:function(jparam){
		var id = jparam.id;									//容器id
		var streamer = jparam.streamer;							//流媒体服务器地址
		var file = jparam.file?jparam.file:null;								//播放的文件名
		var playlist = jparam.playlist?jparam.playlist:null;	//播放列表的url地址
		var image = jparam.image?jparam.image:"";			//预览图片
		var height = jparam.height?jparam.height:400;		//播放器高度
		var width = jparam.width?jparam.width:800;			//播放器高度
		var auto = true==jparam.auto?true:false;			//是否自动播放，默认为false

		if(null==playlist){
			jwplayer(id).setup({
			    flashplayer: WDK_ROOT+'/core/js/lib/jwplayer/player.swf'
			    ,file:file
	//		    ,file:WDK_ROOT + '/core/js/lib/jwplayer/playlist.xml'
			    ,streamer: streamer
			    ,controlbar: 'bottom'
			    ,width: width
			    ,height: height
			    ,image:image
			    ,autostart:auto
			});
		}else{
			jwplayer(id).setup({
			    flashplayer: WDK_ROOT+'/core/js/lib/jwplayer/player.swf'
			    ,file:playlist	//'wdk?action=pub.jwplayer&method=loadlist
//			    ,file:WDK_ROOT + '/core/js/lib/jwplayer/playlist.xml'			示例列表，需要后台构建
			    ,playlist:'none'
			    ,repeat:'always'
			    ,controlbar: 'bottom'
			    ,width: width
			    ,height: height
			    ,image:image
			    ,autostart:auto
			   
			});
		}
	},
	player_close:function(jparam){
		var id = jparam.id;		
		try{
			//$("#"+id).remove();//其中chart就是包含flash的div的id
			jwplayer(id).stop();
		}catch(e){
		}
	},
	//显示图片
	showimg:function(jparam){
		var id = jparam.id;
		var fileid = jparam.fileid;
		var path = jparam.path?jparam.path:'image/upload';
		var arr = [];
		arr.push('<img src="'+_OSS+'/'+path+'/'+fileid+'" style="height:100%;width:100%">');
		$("#"+id).html(arr.join(''));
	}
	
});